A necessary condition for such an $n$ to exist is that $m$ be square-free. However, is it sufficient? If yes, how do you find the smallest such $n$?
Examples: In $\mathbb{Z}/6\mathbb{Z}$ $n = 3$ works: working mod 6, we have $$1^3 = 1, 2^3 = 8 \equiv 2, 3^3 = 27 \equiv 3, 4^3 = 64 \equiv 4, 5^3 = 125 \equiv 5.$$
Similarly, in $\mathbb{Z}/10\mathbb{Z}$ $n = 5$ works. Note that $ 6 = 2 \cdot 3$ and $10 = 2 \cdot 5$ are both square-free.
If $n$ is not square free, say $n = 45 = 3^2 \cdot 9$, then we can divide $n$ be some prime whose square divides $n$ to get a number $a$ (in this case $45/3 = 15$), and $a$ to any power $n > 1$ is always 0 mod n, so in particular $a^n$ will never be $a$ mod $n$.
Now consider $m = 1309 = 7 \cdot 11 \cdot 17$. Is there an $n > 1$ such that $1^n = 1, \ldots, 1308^n = 1308$ (mod 1309)?