Above are the free body diagrams for each mass. The net force on the first mass is
The net force on the second mass is
Applying and we have
and