#include <iostream>
#define LL long long
using namespace std;
LL quickPow( LL a, LL b, LL p )
{
LL res=1, base=a;
while ( b )
{
if ( b & 1 ) res = res*base%p;
base = base*base%p;
b >>= 1;
}
return res;
}
int main()
{
LL a, b, p, s;
cin >> a >> b >> p;
s = quickPow(a, b, p)%p;
cout << s << endl;
return 0;
}