def primeFactor(N): i, n, ret, d, sq = 2, N, {}, 2, 99 while i <= sq: k = 0 while n % i == 0: n, k, ret[i] = n//i, k+1, k+1 if k > 0 or i == 97: sq = int(n**(1/2)+0.5) if i < 4: i = i * 2 - 1 else: i, d = i+d, d^6 if n > 1: ret[n] = 1 return ret # Euler's Totient Function def ETF(N): pf = primeFactor(N) a = 1 for p in pf: a *= (p-1) * (p ** (pf[p] - 1)) return a def powtower(m, L): if not L: return 1 def subcalc(m, L): a = L[0] if len(L) == 1: return a s = subcalc(ETF(m), L[1:]) if a == s == 0: return 1 # 0 の 0 乗はここで定義 if a == 1: return 1 if s <= 100: return a ** s # a > 1 かつ s > 100 なら a ** s は十分大きいので適当に小さくしてよい return pow(a, s, m) + m * 100 return subcalc(m, L) % m A, N, M = map(int, input().split()) print(powtower(M, [A] * min(N, 1000)))