So let's think about this problem step by step. Denote $A$ the event of drawing from bag $1$, and $B$ the event from drawing from bag $2$.
We must get either $m$ times in a row $A$, or $m$ times $A$ and $1$ time $B$, $\cdots$, or $m$ times $A$ and $n-1$ times $B$, but the important thing is that the sequence should always end in $A$. Now, if we assumed there was no order, the probability of getting $m$ times $A$ and $k$ times $B$ would be $\frac{1}{2^k} \times \frac{1}{2^m}$. But there is an order. Say $n=2$, $m=3$. We can get something like $AAA$, or $BAAA$, or $ABAA$, or $AABA$. To find the number of possible combinations with $k$ events $B$,just think about it as choosing $k$ positions for $A$ between $m+k-1$ choices. So $\binom {m+k-1}{k}$
The probability is then
$$p = \sum_{k=0}^{n-1} \binom {m+k-1}{k}\frac{1}{2^{k+m}}$$