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