# problem 1 P = 129402307 N = input() M = input() N = N[::-1] mod_N = 0 for i in range(len(N)): mod_N += pow(10, i)*int(N[i]) mod_N %= P if mod_N == 0: print(0) exit else: M = M[::-1] mod_M = 0 for i in range(len(M)): mod_M += pow(10, i)*int(M[i]) mod_M %= (P-1) print(pow (mod_N, mod_M, P) ) exit