a, b, p = list(map(int, input().split())) def fast(a, b, p): if b == 0: return 1%p if b%2 == 0: return (fast(a, b//2, p))*2%p if b%2 == 1: return fast(a, b-1, p)a%p print(fast(a,b,p))