N = int(input()) M = int(input()) MOD = 129402307 N %= MOD M %= MOD - 1 if N == 0 and M == 0: print(0) else: print(pow(N, M, MOD))