Note: I am not asking anything pertaining to the physics of this question; only the mathematics. The physics is just given as a context to the problem for those interested, as opposed to simply saying "simplify this equation".
The double ball drop problem is as follows:
A ball of mass $m$ is placed on top of a ball of mass $M$ (where $m < M$), and the balls are dropped simultaneously from some height $h$. When the balls hit the floor, the ball on top will shoot upwards. What is the velocity of this ball at the moment it shoots upwards?
Here is a picture of accompany this description:

I have attempted to solve this problem, but am stuck with the following equation:
$$\sqrt{\frac{2gh(m + M) - mv_m^2}{M}} = \frac{(m + M)\sqrt{2gh} - mv_m}{M}$$
What I ask is to help isolate $v_m$. I attempted to using the quadratic equation, but that resulted in a very challenging equation that I am unable to simplify. I feel as though there may be an easier way to solve for $v_m$.
Any help is appreciated.
\begin{array}{ccc} \sqrt{\frac{2gh(m + M) - mv_m^2}{M}} &=& \frac{(m + M)\sqrt{2gh} - mv_m}{M} \\ \\ \frac{2gh(m + M) - mv_m^2}{M} &=& \frac{((m + M)\sqrt{2gh} - mv_m)^2}{M^2} \\ \\ (2gh(m + M) - mv_m^2)M &=& ((m + M)\sqrt{2gh} - mv_m)^2 \\ \\ (2gh(m + M) - mv_m^2)M &=& 2gh(m + M)^2 - 2\sqrt{2gh}(m + M)mv_m + m^2v_m^2 \\ \\ 2gh(m + M)M - mMv_m^2 &=& 2gh(m + M)^2 - 2\sqrt{2gh}(m + M)mv_m + m^2v_m^2 \\ \\ 2gh(m + M)M &=& 2gh(m + M)^2 - 2\sqrt{2gh}(m + M)mv_m + (m^2+mM)v_m^2 \\ \\ 2gh(m + M)M &=& 2gh(m + M)^2 - 2\sqrt{2gh}(m + M)mv_m + m(m+M)v_m^2 \\ \\ 2ghM &=& 2gh(m + M) - 2\sqrt{2gh}mv_m + mv_m^2 \\ \\ 0 &=& 2ghm - 2\sqrt{2gh}mv_m + mv_m^2 \\ \\ 0 &=& m(2gh - 2\sqrt{2gh}v_m + v_m^2) \\ \\ 0 &=& m(\sqrt{2gh} - v_m)^2 \\ \\ \end{array} Hence $v_m = \sqrt{2gh}$.