Because energy is conserved, we know that the kinetic energy of the block+bullet has to equal the energy from the compressed spring. This gives the equation
(1/2)(m+M)V2 = (1/2)kd2
where V is the speed of both the block and bullet... and it's unknown. We can find this V is by using conservation of momentum: the momentum before the bullet hits the block is equal to the momentum after the bullet hits the block (remember, momentum is p=mv). This gives the equation
m*v = (m+M)V
-> V = m*v/(m+M)
Now we can plug V into the first equation, and solve for v
(1/2)(m+M)m2*v2/(m+M)2 = (1/2)kd2
-> m2*v2/(m+M) = kd2
-> v2 = kd2(m+M)/m2
-> v = √(kd2(m+M)/m2) = √[(d2/m2)(m+M)k] = (d/m)√(k(m+M))