I presume the problem is in setting up the Lagrangian? I will use two generalized coordinates: x and . Take a look at the mass M first. I am setting the 0 point for the GPE to be at the equilibrium position of the spring. So

and

The swinging mass m is a bit more of a problem. The potential energy is easy enough:

where y is the length of the string.

For the kinetic energy we have the downward motion of the mass m to contend with as well as the radial motion of the swing. So we have two terms:

The Lagrangian will be total T minus total V:

-Dan