then just take M' + m as a whole system ... (note we can take a group of bodies as a single system only if all the bodies therin have the same accl^n .... note accl^n is a vector... so same accl^n also means same direction...)
So T = (M' + m).a and Mg - T = Ma or M = T/(g - a) = (M' + m).a/(g - a) = (M' + m).g.tan@/(g - g.tan@) = (M' +m). tan@/(1 - tan@) = (M' + m)/(cot@ - 1)