The force exerted by $m$ on $M$ won't be equal to $F$ - it will be a smaller force, $f$.
We can find $f$, if we consider that both masses will move with the same acceleration, i.e., $a=(F-f)/m=f/M$.
Adding some details to address additional questions in the comments.
- Regarding the interpretation of the Newton's third law.
According to Wikipedia, the law says:
When one body exerts a force on a second body, the second body
simultaneously exerts a force equal in magnitude and opposite in
direction on the first body.
So we can say that when body A exerts a force on body B, body B exerts an equal in magnitude and opposite in direction force on body A. So there are only two bodies involved and the equal in magnitude and opposite in direction forces are applied to the same point of contact or, more realistically, if the bodies interact over a finite surface, to the same surface of contact.
The diagram below shows how this is applicable to the problem at hand.
A finger pushes $m$ with force $F$ and, therefore, $m$ pushes the finger with force $-F$. Similarly, $m$ pushes $M$ with force $f$ and $M$ pushes back with force $-f$.
If M was immovable and, as a result, m could not move either, we could conclude, based on the Newton's second law, that, since the acceleration of $m$ is zero, the sum of forces acting on it must be zero as well and, therefore, $f$ must be equal $F$.
Otherwise, there is no law that says that $f$ must be equal to $F$, since these forces act between different pairs of objects.
- You are asking why $m$ and $M$ are moving together.
The only reason $M$ starts moving in the first place is because it is pushed by $m$. Let's say, $M$, somehow, was able to gain an extra speed and get separated from $m$. As soon as that happened, $f$ would become zero and, therefore, $M$ would stop accelerating. On the other hand, the force acting on $m$, $F-f$, would increase and, therefore, its acceleration would increase, so it would immediately catch up with $M$.
Based on that logic, as long as we keep pushing $m$, even if the force is decreasing, $m$ and $M$ will move together.