M varies directly as n and inversely as the square of p. If M = 3, when n = 2 and p = 1, find M in terms of n and p.