The system is conservative; it has two degrees of freedom. We use the generalized coordinates x and ϕ as shown in the figure. With the zero-level of the potential of the force m2g chosen at the height of the mass m1, we have
into the Lagrange equations
yields the coupled equations of motion