Balloon with Weights

 
The weight at first is Mg. The total force at first is -Ma.
The force up at first is B=Mg-Ma. We want to have a total force
of (M-m)a and a weight of (M-m)g at the end.
(M-m)a  =  B-(M-m)g=Mg-Ma-Mg+mg=mg-Ma
m  =  \frac{2Ma}{a+g}.