#include<cstdio>
#include<iostream>
using namespace std;
unsigned long long n,m,k;
unsigned long long calc(unsigned long long a,unsigned long long b){
unsigned long long tot=0;
for(;b;a=(a<<1)%k,b=(b>>1)) if(b&1) tot=(tot+a)%k;
return tot;
}
unsigned long long Pow(){
unsigned long long res=1;
for(;m;m>>=1,n=calc(n,n)%k) if(m&1) res=calc(res,n)%k;
return res;
}
int main(){
freopen("helpless.in","r",stdin);
freopen("helpless.out","w",stdout);
cin>>n>>m>>k;
cout<<Pow()<<endl;
}