#include <iostream>
using namespace std;
typedef unsigned long long ull;
int main(void)
{
ull a,b,q;
scanf("%lld%lld%lld",&a,&b,&q);
ull sum = 1 % q;
while (b)
{
if (b & 1) sum = sum * a % q;
a = a * a % q;
b >>= 1;
}
printf("%lld",sum);
return 0;
}