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