Given that, Bullet of $\operatorname{mass}= m$
Block of mass $= M$
Velocity $= v$ As the bullet comes to rest with respect to the block, the two behaves as one body.
Let $V$ be the velocity of the combination Applying the conservation linear momentum,
$( m + M ) V = mv + Mu$
$V =\frac{ mv }{( m + M )} \ldots ( I )$
As block will rise to a height $h$ Potential energy of combination = Kinetic energy of the combination
$( m + M ) gh =\frac{1}{2}( m + M ) V ^{2}$
$2 gh =\left(\frac{ mv }{ m + M }\right)^{2}$
$v =\frac{ m + M }{ m } \sqrt{2 gh }$
Hence, the initial velocity $v$ is $\frac{ m + M }{ m } \sqrt{2 gh }$