'''No.2007 Arbitrary Mod (Easy) ''' a, n, M = map(int, input().split()) assert 2 <= a <= 1000 assert 2 <= n <=10 ** 18 def remainder(): if M != 0: return a ** n % M else: return None print(remainder(a, n, M))