When the two balls arrive at the ground, they both have speed $V=\sqrt{gh}$ and are travelling downward. Break the interaction down into two stages. First, $m_2$ collides with the ground. Then, $m_1$ and $m_2$ collide (they cannot collide before $m_2$ collides with the ground because they have the same velocity). After this, $m_1$ necessarily has positive velocity (which can be shown). $m_2$ can have positive or negative velocity, depending on the ratio $m_1/m_2$. If it has negative velocity, it will collide with the ground again.
First, let's deal with $m_2$ colliding with the ground. This can be modelled as an elastic collision by thinking of the ground as a ball with mass that tends to $\infty$. Carrying out the math, it's pretty easy to show that the ground doesn't move and $m_2$ just has the sign of its velocity switched.
Now the second collision is between $m_1$ moving downward with speed $V$ and $m_2$ moving upward, also with speed $V$. The equations to solve are conservation of momentum:
$$m_1v_{1,i} + m_2v_{2,i} = m_1v_{1,f} + m_2v_{2,f}$$
putting in the known velocities gives:
$$m_1(-V) + m_2V = m_1v_{1,f} + m_2v_{2,f}~~~~~~~~~~~~~~(1)$$
The second equation is for conservation of energy. I'll consider the change in energy between just before and just after the collision, so there is no change in heights and therefore no change in potential energy. This gives:
$$\frac{1}{2}m_1v_{1,i}^2 + \frac{1}{2}m_2v_{2,i}^2 = \frac{1}{2}m_1v_{1,f}^2 + \frac{1}{2}m_2v_{2,f}^2$$
(the $\frac{1}{2}$ aren't necessary since they cancel out, but you may be used to seeing them there). Again, putting in the known velocities:
$$\frac{1}{2}m_1(-V)^2 + \frac{1}{2}m_2V^2 = \frac{1}{2}m_1v_{1,f}^2 + \frac{1}{2}m_2v_{2,f}^2~~~~~~~~~~~~~~(2)$$
Now we have 2 equations ($(1)$ and $(2)$) and 2 unknown quantities $v_{1,f}$ and $v_{2,f}$. They can be solved (I won't go through the details here), and you should get:
$$v_{1,f} = V\frac{3\frac{m_2}{m_1}-1}{\frac{m_2}{m_1}+1}$$
$$v_{2,f} = V\frac{\frac{m_2}{m_1}-3}{\frac{m_2}{m_1}+1}$$
A nice thing to check right now is what happens if $m_1=m_2$ (in this special case the two balls should keep the same speed, but just change directions).
Now you can check that $v_{1,f}$ is actually moving upward (we know that $m_1<m_2$, so this should be pretty obvious). Without knowing the ratio $m_1/m_2$, it isn't clear whether $v_{2,f}$ is positive or negative (but you can, and should, show that $|v_{2,f}|<|v_{1,f}|$, so $m_2$ will not "catch up" to $m_1$ and collide again). If $m_2$ happens to have negative velocity after this collision, it will hit the ground again. Doing the same thing as before, its velocity will just reverse direction and it will immediately be moving upward anyway, so we can just assume it's positive.
Now the only thing left to do is solve for the heights. This is done again using conservation of energy, this time between right after the collision and the instant each ball reaches its maximum height (treat them separately). The relevant equations:
$$\frac{1}{2}m_1v_{1,f}^2 = m_1gh_1$$
$$\frac{1}{2}m_2v_{2,f}^2 = m_2gh_2$$
Solve those for $h_1$ and $h_2$ and you're done!