#include<iostream>
#include<cstdio>
using namespace std;
int a,b,p;
long long ans2;
long long m(int a2,int b2,int p2)
{
long long ans=1,t=a2;
while(b2>0)
{
if(b2%2==1)
{
ans=ans*t%p2;
}
t=t*t%p2;
b2=b2/2;
}
return ans;
}
int main()
{
freopen("dmod.in","r",stdin);
freopen("dmod.out","w",stdout);
scanf("%d%d%d",&a,&b,&p);
ans2=m(a,b,p);
printf("%ld",ans2);
return 0;
}