Why can't we use F=(M+m)a to find the acceleration of the system?
As you see in the photo I have uploaded, I have drawn the Free Body Diagrams of the two blocks separately. I haven't shown the forces in the horizontal direction in the Free Body Diagrams but as you can see in the third diagram, I have considered both the blocks as one system while considering motion in the horizontal direction. So if the frictional force between the blocks is sufficient to resist the weight of the smaller block, it won't fall down and similarly, if the friction between the ground and the block is sufficient the system will be at rest. Otherwise, the equation would be
I hope this helps. :)
You need to include the friction force also. F is not the only force acting on the system.
Do a free body diagram first to solve problems like this.