def is_zero(s): return all(c == '0' for c in s) def str_mod(s, mod): result = 0 for c in s: result = (result * 10 + int(c)) % mod return result n_str = input().strip() m_str = input().strip() mod_p = 129402307 mod_euler = mod_p - 1 m_is_zero = is_zero(m_str) if m_is_zero: print(1 % mod_p) else: a = str_mod(n_str, mod_p) if a == 0: print(0) else: m_mod = str_mod(m_str, mod_euler) exp = m_mod if m_mod != 0 else mod_euler result = pow(a, exp, mod_p) print(result)