Why is Pakistan so densely populated despite mountains and deserts making up large percent of country

Like they have population of close to 245 million, and population density of 302/km2, which is similar to that of Japan and more than that of UK. That is despite most of the country being made up of mountains and deserts. Why is that?