Due to F1 and F2 block of mass m1 and m2 will experience different acceleration and experience an inertia force
If m1 displaces by a distance x1 and x2 by m2 the maximum extension of the spring is x1 + m2.
Work done by the blocks = energy stored in the spring.