Solution (source code)

= Solution

Hamilton's equations give
$$
\dot p_i=n_iH_1(p_1,p_2)\sin\theta,
$$
so
$$
\boxed{n_2p_1-n_1p_2\text{ is conserved}}.
$$
Use
$$
F_2=(n_1q_1+n_2q_2)P_1+q_2P_2.
$$
Then
$$
Q_1=\theta,\quad Q_2=q_2,\quad
p_1=n_1P_1,\quad p_2=n_2P_1+P_2,
$$
and $P_2=p_2-(n_2/n_1)p_1$ is the conserved combination. The transformed Hamiltonian depends on $Q_1$ but not $Q_2$. Thus $H$ and $P_2$ are two independent first integrals in involution for two degrees of freedom, proving <Integrable systems>[Liouville integrability].