# import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = list(input())[:-1] M = list(input())[:-1] N = [int(i) for i in N] M = [int(i) for i in M] mod = 129402307 def f(X,m): n = len(X) I = 1 now = 0 for i in range(n-1,-1,-1): now += X[i]*I now %= m I *= 10 I %= m return now m = f(M,mod-1) n = f(N,mod) if N == [0]: print(0) exit() if n==0: if m==0: print(1) else: print(0) exit() if m==0: print(1) exit() print(pow(n,m,mod))