1. 

/**
* FWP: Ausgewaehlte Probleme aus dem ACM
*
* Problem: 374 - Big Mod
* Accepted: 0.120
* @author Evgeni Pavlidis

*/

import java.io.*;
import java.util.*;

class Main {

/**
* Recursively calculates the b^p mod m
*/
public static long exp(long b,long p,long m)
{
if(p==0)
return 1;

if(p==1)
return b % m;

long tmp = exp(b, p / 2, m) % m;
tmp = (tmp * tmp) % m;

if(p % 2 == 0)
return tmp;

return tmp * b % m;
}


public static void main(String...args)
{
long b,p,m;
Scanner scanner = new Scanner(System.in);

while(scanner.hasNextInt())
{
b = scanner.nextInt();
p = scanner.nextInt();
m = scanner.nextInt();

System.out.println(exp(b,p,m));
}
}
}