$m^{\varphi(n)}
= 1 \text{ mod } n$
where $\varphi(n)$ is the totient of n.The totient of a number is simply the number of Integers that are smaller, and coprime (i.e. no common factors).
This allows us to come up with a simple (though not foolproof) test for prime numbers.
If n is a prime number p, then the number of smaller Integers that are coprime, are all of them. Thus $\varphi(p) = p-1$ for a prime number, and $m^{(p-1)} = 1 \text{ mod } p$ should be true for all the numbers m, smaller than p.