Initial kinetic energy of the block when the bullet strikes.
`=(1)/(2)(m+M)v^(2)`
Due to this kinetic energy, the block will block will rise to a height h. Its potential energy =(m+M) gh
So, from the law of conservation of energy
`(1)/(2)(M+m)v^(2)=(M+m) gh implies v=sqrt(2gh)`