import java.util.Scanner;
public class Main {
public static long binPow(long a, long b, int m) {
a %= m;
if (b == 0) return 1;
else if (b % 2 == 0) {
return binPow((a * a) % m, b / 2, m);
}
else return (a * binPow(a, b - 1, m)) % m;
}
public static void main
(String[] args
) { Scanner scanner
= new Scanner
(System.
in); long a = scanner.nextLong();
long b = scanner.nextLong();
int m = scanner.nextInt();
System.
out.
println(binPow
(a, b, m
)); }
}
aW1wb3J0IGphdmEudXRpbC5TY2FubmVyOwoKcHVibGljIGNsYXNzIE1haW4gewogICAgcHVibGljIHN0YXRpYyBsb25nIGJpblBvdyhsb25nIGEsIGxvbmcgYiwgaW50IG0pIHsKICAgICAgICBhICU9IG07CiAgICAgICAgaWYgKGIgPT0gMCkgcmV0dXJuIDE7CiAgICAgICAgZWxzZSBpZiAoYiAlIDIgPT0gMCkgewogICAgICAgICAgICByZXR1cm4gYmluUG93KChhICogYSkgJSBtLCBiIC8gMiwgbSk7CiAgICAgICAgfQogICAgICAgIGVsc2UgcmV0dXJuIChhICogYmluUG93KGEsIGIgLSAxLCBtKSkgJSBtOwogICAgfQogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIFNjYW5uZXIgc2Nhbm5lciA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgbG9uZyBhID0gc2Nhbm5lci5uZXh0TG9uZygpOwogICAgICAgIGxvbmcgYiA9IHNjYW5uZXIubmV4dExvbmcoKTsKICAgICAgICBpbnQgbSA9IHNjYW5uZXIubmV4dEludCgpOwogICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihiaW5Qb3coYSwgYiwgbSkpOwogICAgfQp9