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