#include <iostream>
using namespace std;
long binpow (long a, long n, long m) {
if (n == 0)
return 1 % m;
if (n % 2 == 1)
return (binpow (a, n - 1, m) * a) % m;
else {
return binpow ((a * a) % m, n/2, m);
}
}
int main() {
long a, b, m;
cin >> a >> b >> m;
cout << binpow (a, b, m);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpsb25nIGJpbnBvdyAobG9uZyBhLCBsb25nIG4sIGxvbmcgbSkgewoJaWYgKG4gPT0gMCkKCQlyZXR1cm4gMSAlIG07CglpZiAobiAlIDIgPT0gMSkKCQlyZXR1cm4gKGJpbnBvdyAoYSwgbiAtIDEsIG0pICogYSkgJSBtOwoJZWxzZSB7CgkJcmV0dXJuIGJpbnBvdyAoKGEgKiBhKSAlIG0sIG4vMiwgbSk7Cgl9Cn0KIAppbnQgbWFpbigpIHsKICAgIGxvbmcgYSwgYiwgbTsKICAgIGNpbiA+PiBhID4+IGIgPj4gbTsKICAgIGNvdXQgPDwgYmlucG93IChhLCBiLCBtKTsKICAgIHJldHVybiAwOwp9