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