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