def power(a,k,n) return( 0 ) if ( a == 0 || n == 0 ) return( 0 % n ) if ( k == 0 ) currentMod = a % n; currentValue = ( ( k & 1 ) > 0 ) ? currentMod : 1; k >>= 1 while ( k > 0 ) do currentMod = ( currentMod * currentMod ) % n; if ( ( k & 1 ) > 0 ) currentValue = ( currentValue * currentMod ) % n; end k >>= 1 end return( currentValue ); end def solve(a,b,m,d) return 1 if b == 0 return a if b == 1 || d == 0 mod=(m ** d) return power(a,solve(a,b-1,m,d-1),mod) end a,b,m=gets.split.map(&:to_i) puts solve(a,b,m,140)%m