#include
#include
#include
#include
#include
#include
using namespace std ;
int lxx ( long long bb , long long pp , long long kk )
{
long long b = bb , p = pp , k = kk , ans = 1 ;
while ( p > 1 )
{
if ( p % 2 == 1 ) ans = ( ans % k ) * ( b % k ) % k ;
p /= 2 ;
b = ( b % k ) * ( b % k ) % k;
}
ans = ans * ( b % k ) % k ;
return ans ;
}
int main ( )
{
int a ,b , c ;
cin >> a >> b >> c ;
cout << lxx ( a , b , c ) ;
return 0 ;
}