your initial energy of $m_1$ is all potential $m_1gh$, where $h$ is the elevation difference from where $m_1$ at the start to where it will go at the bottom of its travel.
at the bottom the spring will contract by $x$ along the ramp. now you need an angle between the ramp and the vertical, let's say $\theta$. so the initial energy of $m_2$ is also all potential $m_2gx\cos\theta$.
the final energy is all the tension of the spring, because at the bottom point all stops moving: $kx^2/2$. so you get the equation:
all this assuming that when $m_1$ hits $m_2$ they stick together until they reach the bottom. obviously, this isn't happening. if $m_1=m_2$, then $m_1$ will transfer its momentum to $m_2$, which will start moving down, then $m_1$ and $m_2$ will hit again etc. this seems to may have a resonance condition when they'll keep bounding forever, or a stable solution when this all stops. I'm too lazy to solve this part