The entire mass of the moving apparatus is $M+m$. The gravitational force acting on $m$ will create a tension $T$ in the cord and cause the apparatus to move to the right with an acceleration of $a_{x}$. The tension in the cord is then given by $T=(M+m)a_{x}$. This tension acts in the positive direction on m, so the total force acting on m is given by $f_{m}=T-mg=(M+m)a_{x}-mg$. Note that as the apparatus moves one unit to the right, m drops two units. This means that if $a_{y}$ is the acceleration of $m$, then $a_{y}=-2a_{x}$. The acceleration of m can now be determined as follows.
\begin{eqnarray*} f_{m} & = & ma_{y}=(M+m)a_{x}-mg,\\ ma_{y} & = & -(M+m)a_{y}/2-mg,\\ -2ma_{y} & = & (M+m)a_{y}-2mg,\\ 2ma_{y}+(M+m)a_{y} & = & 2mg,\\ a_{y} & = & \frac{2mg}{M+3m}. \end{eqnarray*}
The formula for constant acceleration gives
\begin{eqnarray*} h & = & \frac{1}{2}a_{y}t^{2},\\ t & = & \sqrt{\frac{2h}{a_{y}}},\\ & = & \sqrt{\frac{M+3m}{mg}h}. \end{eqnarray*}