Given a and m, we can find a^(-1) mod m by calculating a^(phi(m)-1) mod m, where phi(m) is Euler's totient function that counts the positive integers less than or equal to m that are relatively prime to m. This method works if a and m are relatively prime.