This isn't as simple as just equating the electrostatic force with weight at a distance of $\displaystyle h-R$ from the centre of the sphere. Before the electrostatic force gets large enough for this there will be a point where the force will be strong enough such that the last charged particle will fall but the kinetic energy it gains from the fall (due to gravity) will be exactly balanced by the electrostatic P.E. gained in moving closer to the charged sphere.
Electrostatics
First lets analyse the electrostatic force.
When each charged particle lands in the sphere we can assume that the charge will be uniformly distributed around the spherical shell. Also we can assume the opening is negligibly small and so its effect can be ignored in the final electrostatic force. So we simply need to work out the electrostatic force due to a charged metal spherical shell of charge $\displaystyle nq$.
Now the force due to a an electrically charged sphere is (analogous to gravity) equivalent to the force due to a particle at its geometrical centre of the same charge. Now due to the superpositional nature of electric fields we can note that if we were to combine the shell with a sphere (of the same charge density) fitting perfectly inside it we would have a slightly larger sphere. This larger sphere will still be equivalent to a charged particle of equal charge at its centre. Hence, the electrostatic force due to a charged spherical shell must be the same as a particle at its centre of the same charge.
So at a distance $\displaystyle x$ from the centre of the metal sphere the force, $\displaystyle F_e$, on the $\displaystyle {n+1}^{\text{th}}$ charged particle (Coulomb's law) would be
$\displaystyle \color[rgb]{0,0,1} \boxed{F_e = \frac{n q^2}{4 \pi \epsilon_0 x^2}}$.
Mechanics
For the $\displaystyle {n+1}^{\text{th}}$ particle to be unable to enter the sphere we require that gravitational potential energy lost in the fall must be less than or equal to the electrostatic potential energy gained.
The work, $\displaystyle W$, done in taking a charged particle from a distance $\displaystyle h-R$ to $\displaystyle R$ away from the centre of the sphere is then
$\displaystyle W= -\frac{n q^2}{4 \pi \epsilon_0} \int_{h-R}^{r} \frac{1}{x^2} \, \mathrm{d}x$,
$\displaystyle = \frac{n q^2 }{4 \pi \epsilon_0} \frac{h-2R}{r(h-R)}$.
The gravitational potential energy lost is simply $\displaystyle mg (h-2R)$ so equating we have
$\displaystyle mg (h-2r) = \frac{n q^2 }{4 \pi \epsilon_0} \frac{h-2R}{R(h-R)}$,
$\displaystyle \color[rgb]{0,0,1} \boxed{\Leftrightarrow n = \frac{4 \pi \epsilon_0 m g (h-R) R} {q^2}}$.
Strictly speaking as this stands it may not be an integer and so $\displaystyle n$ is really this value rounded up to nearest integer above it.