You might profit if you research "Atwood machine" on the web.
Here is a compact treatment but there is plenty more including videos. Please read carefully and try to understand how one proceeds to solve such problems. The method is straightforward:
- Choose a system, in this case one of the masses, say ##M##.
- Find the net force (sum of all the forces acting on it) ##F_{\text{net,M}}.##
- Set this sum equal to the mass of the system times its acceleration. This gives you one equation, ##F_{\text{net,M}}=Ma##
- Repeat for the other mass, ##m_2##. Note that if ##M## accelerates up, ##m_2## must accelerate down. You should get a second equation ##F_{\text{net},\text{m}_{2}}=-m_2a.##
- Combine the two equations to find the acceleration.
See how this plan is executed in the link I provided. The link does not provide the tension, but you can find it easily with a little algebra from either ##F_{\text{net,M}}=Ma## or ##F_{\text{net},\text{m}_{2}}=-m_2a## if you have an expression for the acceleration ##a##.