Replacing M1 by a mass M1/4, the gas will expand against the pressure (Pexternal):
The mass is lifted and the gas expand until the pressure is P1/4. The new volume is 4V1. The work is performed: Work = w1 = (M1/4)gh, where h is the change in height of the mass.
This work can also be expressed in terms of the external pressure. w1 = -Pex (V2-V1) = -P1/4 (4V2-V1) = -3/4 (P1V1)