First, I thought of the forces which are acting upon the piston.
F1 + G = F2, where F1 = p1 * S and F2 = p2 * S
p1 + mg/S = p2
I figured that before and after the gas' temperature rises, the piston has to be at equilibrium, so p2 - p1 = p2' - p1'.
p1V1 = niu * R * T1
p2V2 = niu * R * T1 =>...