N = int(input()) M = int(input()) P = 129402307 N %= P M %= (P-1) print(pow(N,M,P))