import sys input=lambda: sys.stdin.readline().rstrip() n=int(input()) m=int(input()) mod=129402307 n%=mod m%=mod-1 print(pow(n,m,mod))