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)