n = str(input()) m = str(input()) if m == '0': print(0) exit() if n == '0': print(1) exit() mod = 129402307 N = 10**6 P0 = [0]*N P0[0] = 1 for i in range(1, N): P0[i] = 10*P0[i-1] P0[i] %= mod P1 = [0]*N P1[0] = 1 for i in range(1, N): P1[i] = 10*P1[i-1] P1[i] %= mod-1 n = list(n) m = list(m) n.reverse() m.reverse() y = 0 for i, c in enumerate(m): y += int(c)*P1[i] y %= mod-1 x = 0 for i, c in enumerate(n): x += int(c)*P0[i] x %= mod if x == 0: print(0) exit() ans = pow(x, y, mod) print(ans)