a = int(input()) b = int(input()) mod = 129402307 if a % mod == 0: print("0") exit() a %= mod b %= (mod-1) print(pow(a,b,mod))