mod = 129402307 n = readline().to_i % mod m = readline().to_i if n == 0 p 0 elsif m == 0 p 1 else p n.pow(m % (mod - 1), mod) end