Let $p$ be a prime and let $\Bbb Z(p)$ be the ring of integers mod $p$. Define a function $f:\Bbb Z(p)\to \Bbb Z(p)$ by $$f(a)=\begin{cases}0, &a=0\\ a^{-1},&a \ne0\end{cases}$$ Find all primes $p$ for which $f$ is a ring isomorphism.
I have checked that $f$ is a homomorphism, and it is surjective obvious. But I don't know how to find $p$ to make it injective.