#include <iostream>
using namespace std;
typedef long long ll;
int quick(int a, int b, int p){
ll res = 1;
while(b){
if(b & 1) res = res * a % p;
b >>= 1;
a = (ll)a * a % p;
}
return res % p;
}
int main(){
int a, b, p;
cin >> a >> b >> p;
cout << quick(a, b, p);
return 0;
}