#include<cstdio>
#include<iostream>
using namespace std;
inline long long get();
inline long long pow();
long long b,p,k;
int main()
{
freopen("dmod.in","r",stdin);
freopen("dmod.out","w",stdout);
b=get(),p=get(),k=get();
printf("%lld",pow());
return 0;
}
inline long long pow()
{
long long ans=1;
while(p)
{
if((p%2))
{
(ans*=b)%=k;
p-=1;
}
(b*=b)%=k;
p>>=1;
}
return ans%k;
}
inline long long get()
{
long long t=0;char c=getchar(),j=1;
while(!isdigit(c))
if(c=='-')j=-1,c=getchar();
else c=getchar();
while(isdigit(c))
t=(t<<3)+(t<<1)+c-'0',
c=getchar();
return j*t;
}