If m is stationary wrt M,
then take FBD of m..
Forces are N towards right ... mg downwards and μN upwards.
So, mg = μN ... (i)
N=ma ...(ii)
Now both have common acceleration a (say)
Drawing FBD of M in horizontal direction,
F-N = Ma ... (iii)
Solving (ii) and (iii)
a = F/(M+m)
so, N = mF/(M+m)
Putting in (i)
mg = μmF/(M+m)
==> F = g/μ(M+m)