Let $q$ be the integer result of dividing $m$ by $n$, and $r$ the remainder of this division. So $m=qn+r$ with $0\le r < n$, and $q$ is the whole number $q=\lfloor\frac{m}{n}\rfloor$.
If you just flip $n$ lights on at a time, after $q$ moves you would have just $r$ lights left. There are a few different cases to consider.
$r=0$:
There are no lights left, so it takes just $q$ moves.
$r+n$ is even, and $q\ge2$.
Flip $q-1$ sets of $n$ lights on, so you have $n+r$ lights left. For the next move flip half of those lights on (i.e. $\frac{n+r}{2}$ on) and the rest of the move switch other lights off (i.e. $n-\frac{n+r}{2}$ lights off). This leaves you with exactly $n$ lights off that you switch on in the next move. This takes $q+1$ moves.
Note that we need $q\ge2$ because there must be lights available to switch off in the second-to-last move.
$r$ is even
This is similar to the previous case but using $r$ instead of $r+n$.
Flip $q$ sets of $n$ lights, so you have $r$ lights left. For the next move flip half of those lights on (i.e. $\frac{r}{2}$ on) and the rest of the move switch other lights off (i.e. $n-\frac{r}{2}$ lights off). This leaves you with exactly $n$ lights off that you switch on in the next move. This takes $q+2$ moves.
$r$ odd, $n$ even (i.e. $m$ odd, $n$ even )
This is impossible. If you always flip an even number of lights, then the total number of lights on will always remain even. You can flip all but one of the lights (just ignore one light, acting as if $m$ is one smaller).
$r$ odd, $n$ odd, $q=1$. This is the trickiest case.
As $m=n+r$ is even we must make an even number of total flips. We flip an odd number of lights in each move, so we need an even number of moves.
Flipping $n$ lights is equivalent to flipping all $m$ of them, and then flipping $m-n=r$ of them back again. As we need an even number of moves and flipping all of them an even number of times does nothing, this case is equivalent to turning on $m$ lights using moves of $r$ lights each time. This game will therefore fall under one of the previous cases that have already been solved.
For example, $m=8, n=5$. We have $q=1$ and $r=3$. This is equivalent to the $m=8$, $n'=r=3$ case. In this new problem we have $m=2*n'+2$, so $q'=2$, $r'=2$. Since $r'$ is even we can solve it in $q'+2=4$ moves.
Note that $q'$ is always at least $2$.
Here is a pictorial view of the various cases: