Let x be the compression in the spring when the bar m2 is about to shift. Therefore at this moment spring force on m2 is equal to the limiting friction between the bar m2 and horizontal floor. Hence
kspringx=km2g ......(1) where k is the coefficient of friction.
The spring has to be extended by x to make the block m2 move.
Notice that the bar2 is just about to move, it hasn't started moving. The work done by the constant force
F is a sum of work done on the spring to stretch it by x and moving the bar m1 by x.
∴Fx=12kspringx2+km1gx
⇒F=12(km2g)+km1g=kg(m1+m22) where we have substituted
kspringx=km2g from (1)
Comparing with Fmin=kg(m1+m2x), we get x=2