/*
  Copyright 2011 Marek "p2004a" Rusinowski
  Exponentiation by squaring
*/
#include <cstdio>

int pow (int a, int b, int c) {
  if (!b) return 1;
  int tmp = pow(a, b/2, c);
  return (((tmp * tmp) % c) * (b & 1 ? a : 1)) % c;
}

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  printf("%d\n", pow(a, b, c));
  return 0;
}
