#include <iostream>
using namespace std;
long binpow (long a, long n, long m) {
long res = 1;
while (n) {
if (n & 1) {
res *= a;
res %= m;
}
a *= (a % m);
a %= m;
n >>= 1;
}
return res % m;
}
int main() {
long a, b, m;
cin >> a >> b >> m;
cout << binpow(a, b, m);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsb25nIGJpbnBvdyAobG9uZyBhLCBsb25nIG4sIGxvbmcgbSkgewogICAgbG9uZyByZXMgPSAxOwogICAgd2hpbGUgKG4pIHsKICAgICAgICBpZiAobiAmIDEpIHsKICAgICAgICAgICAgcmVzICo9IGE7CiAgICAgICAgICAgIHJlcyAlPSBtOwogICAgICAgIH0KICAgICAgICBhICo9IChhICUgbSk7CiAgICAgICAgYSAlPSBtOwogICAgICAgIG4gPj49IDE7CiAgICB9CiAgICByZXR1cm4gcmVzICUgbTsKfQogCmludCBtYWluKCkgewogICAgbG9uZyBhLCBiLCBtOwogICAgY2luID4+IGEgPj4gYiA+PiBtOwogICAgY291dCA8PCBiaW5wb3coYSwgYiwgbSk7CiAgICByZXR1cm4gMDsKfQ==