A thermally insulated container with a constant cross sectional area $A$ is separated into an upper and lower compartment by a divider of mass $M$. The two compartments are filled with certain moles of ideal gas which can exchange heat with one another as the divider is not thermally insulated. A small ball of a certain mass $m$ is stuck to the bottom face of the divider. Initially, the ratio of the volumes of the upper and lower compartments is $3: 1$ and the pressure of the gas in the upper compartment is $p_1$. Then, the ball of mass $m$ falls from the divider and bounces on the bottom of the container, until it eventually comes to rest at the bottom of the lower compartment. If the final ratio of the volumes of the upper and lower compartments is $2: 1$, determine $m$.