import java.util.*;
public class Main{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
long p = input.nextLong();
System.out.println(qmi(a,b,p));
}
public static int qmi(int a,int b,long p){
long res=1%p;long k=a;
while(b!=0){
if((b&1)==1){
res=res*k%p;
}
b=b>>1;
k*=k;
k%=p; //这里不取余好像有的数字不给过,还没相通为什么
}
return (int) res;
}
}