def modpow(n: str, m: str, mod: int) -> int: """巨大数 n, m の n^m % mod を求める (mod は素数)""" def modulo(s: str, m: int) -> int: x = 0 for c in map(int, s): x = (10*x + c) % m return x if n == '0': return 0 a = modulo(n, mod) b = modulo(m, mod-1) # print(f'{a=} {b=}') return pow(a, b, mod) MOD = 129402307 N = input() M = input() ans = modpow(N, M, MOD) print(ans)