x,p,m = map(int,input().split())
t=x**p
r=t%m
print(r)

/**************************************************************
	Problem: 1412
	User: admin
	Language: Python
	Result: Accepted
	Time:203 ms
	Memory:34356 kb
****************************************************************/