There is no such function as soon as $M$ has at least two points. Let's call them $0,1$. Given an $f$, let $x_n=0$ for $n\le f(1)$, forcing us to take $x_{n_1}=0$. Let's say we took $n_1=1$. There are now $f(1)-1$ elements $x_n=0$ left in this initial segment, so if we follow up by a sufficiently long segment of $1$'s, we'll run out of $0$'s eventually and have to make $x_{n_k}=1$.
More precisely, we let $x_n=1$ for $f(1)<n\le f(f(1))$, and then we are forced to take $x_{n_{f(1)}}=1$.
Continuing in this way, we find a sequence with the property that any subsequence satisfying $n_k\le f(k)$ will have infinitely many ones and zeros.