#include<iostream>
using namespace std;
long long pow(long long a , long long b, long long p){
long long ans = 1, base = a;
while(b != 0){
if(b & 1 != 0){
ans = ans * base % p;
}
base = base * base % p;
b >>= 1;
}
return ans;
}
int main(){
long long a,b,p;
cin>>a>>b>>p;
if(b == 0) cout<< 1 % p ;
else cout<<pow(a,b,p);
}