Initial KE = $\frac{1}{2}mv^2$. By conservation of momentum, the final velocity of the combined mass is $V = mv/(m+M)$. Final KE = $\frac{1}{2}(m+M)V^2 = \frac{1}{2}\frac{m^2v^2}{m+M}$. The loss in KE is the difference, which simplifies to $\frac{1}{2}\frac{mM}{m+M}v^2$.