#include<cstdio>
#include<cctype>
using namespace std;
long long ret;
char ch;
long long qin()
{
ret=0;
while(ch=getchar(),!isdigit(ch));
while(ret=ret*10+ch-'0',ch=getchar(),isdigit(ch));
return ret;
}
long long b,p,k;
int main()
{
freopen("dmod.in","r",stdin);
freopen("dmod.out","w",stdout);
b=qin();p=qin();k=qin();
long long Ans=1;
while(p)
{
if(p&1)
{
Ans*=b;
Ans%=k;
}
b*=b;
b%=k;
p>>=1;
}
printf("%lld\n",Ans);
return 0;
}