#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b, p;
cin >> a >> b >> p;
int res=1%p;
while (b){
if(b&1)res=(long long)res*a%p;
a=(long long)a*a%p;
b>>=1;
}
cout << res << endl;
return 0;
}