mod = 129402307 def calc_mod(n, mod): res = 0 for s in n: res *= 10 res += int(s) res %= mod return res N = calc_mod(input(), mod) M = calc_mod(input(), mod - 1) if N == 0: print(0) else: print(pow(N, M, mod))