Molar mass (M) is equal to the mass (m) divided by the moles (n). But, it can be rewritten in terms of moles, which is a variable in the ideal gas equation.
Density is defined by mass (m) divided by volume. Using the equation above and the ideal gas equation we now have these two variables and can thus solve for density. Putting all of this together we get the equations to the right.