import sys sys.set_int_max_str_digits(10 ** 6) input = sys.stdin.buffer.readline N = int(input()) M = int(input()) MOD = 129402307 if Nmod := N % MOD: print(pow(Nmod, M % (MOD - 1), MOD)) elif M == 0: print(1) else: print(0)