A,N = map(int,input().split()) M = 1 cnt = 0 while(10**7>M): M *= A cnt+=1 print(M) if(cnt>N): cnt = N print((A**cnt)%M)