How to find the $n$th term of a repeating pattern What is the nth term of following sequence 
 $1,2,3,4,5,6,1,2,3,4,5,6,\ldots$
$(n, n+1, n+2, n+3,\ldots,$ $,n+p, n, n+1, n+2, n+3,$ $n+4, n+5,$ $\ldots,$ $n+p,$ $n,$ $n+1,$ $\ldots)$
Actually, I am trying to solve the following puzzle
 $6$ girls pick a captain by forming a circle then eliminating every $m$th girl. The 2nd girl in the counting order can choose $m$. If she wants to be captain what's the smallest $m$ she should pick?
 A: The $n$th term of the repeating sequence $1,2,3,4,5,6,1,2,3,4,5,6,\ldots$ can be written
$$n-6\lfloor{n-1\over6}\rfloor$$
where $\lfloor x\rfloor$ is the greatest integer function.
The OP's real question, about the would-be captain, strikes me as a nice new take on the classic Josephus Problem, which André Nicolas recommended in comments.  That problem is to predict the survivor as a function of the starting number $n$ and the "skip count" $m$.  The OP here is, in effect, asking about the inverse of that function.  I.e., if $S(m,n)$ is the usual "Survivor" function, we can ask about the set $M(n,s)=\{m:s=S(m,n)\}$; the OP wants the smallest member of the set $M(6,2)$.
I'm with the answer given by Michael:  I can't think of any way to find the smallest (or any) element of $M(6,2)$ except by trial and error.  In fact I'll go further:  It's not obvious to me that the set $M(6,2)$ has any elements at all.  Am I missing some elementary reason that the sets $M(n,s)$ are necessarily non-empty?
Added later:  For completeness, here are the results of trial and error:
$$\begin{align}
m&\quad\text{order of elimination}\\
1&\quad123456\\
2&\quad246315\\
3&\quad364251\\
4&\quad421365\\
5&\quad543216\\
6&\quad613254\\
7&\quad136245\\
8&\quad254163\\
9&\quad312645\\
10&\quad436152\\
\end{align}$$
So it is obvious to me now that the set $M(6,2)$ is non-empty, but only because I was able to find its smallest element with a finite amount of computation:  The answer to the OP's question is $m=10$, that being the smallest number for which $s=2$ is the last number "eliminated."
Actually, it's fairly clear that for any given $n$, the sets $M(n,s)$ for $1\lt s\lt n$ can be determined by a finite computation.  That's because the list of permutations that specify the order of elimination, as illustrated above for $n=6$, is periodic with period $\text{lcm}(1,2,\ldots,n)$ (or a divisor thereof).  For $n=6$, the lcm is $60$.  Lucky for me I didn't have to list all $60$.  I doubt I could have done so without making at least one mistake.  (For that matter, I won't guarantee the list I did compute is mistake-free.  I did doublecheck the order of elimination for $m=10$, though, so at the very least the smallest member of $M(6,2)$ is no greater than $10$.)
A: With your notation, $u_k = n-1+\pmod{(k,p)}$, where $\pmod{(k,p)}$ is the smallest positive integer $m$ that verifies $p|(k-m)$.
A: If $m=1$, then 1,2,3,4,5 are eliminated, so 6 is captain.
If $m=2$, then 2,4,6 are eliminated, skip 1, eliminate 3, skip 5, eliminate 1, so 5 is captain.
Repeat for $m=3$, $m=4$, and so on.
I don't know how to calculate it in advance though.
A: The $n$-th term of sequence $1,2,3,4,5,6,1,2,3,4,5,6,\ldots$ is given by $a_n=1+(n-1 \bmod 6)$.
