#include<bits/stdc++.h>
using namespace std;
long b,p,k,ans=1;
long x,y,z;
int main(){
cin>>b>>p>>k;
x=b;y=p;z=k;
while(y>1){
if(y%2==0){
x*=x;
y/=2;
x%=z;
}
else{
ans*=x;
ans%=z;
x*=x;
y/=2;
x%=z;
}
}
ans*=x;
ans%=z;
cout<<ans<<endl;
}