import Control.Applicative

power :: Integral a => (t -> t -> t) -> t -> t -> a -> t
power _ e _ 0 = e
power f e a n = power f (if odd n then f a e else e) (f a a) (div n 2)

-- a^n (mod m)
powerMod :: (Integral a, Integral t) => t -> a -> t -> t
powerMod a n m = power (\x y -> mod (x * y) m) 1 a n

main :: IO ()
main = do
  [m, n] <- map read . words <$> getLine
  print $ powerMod m n 1000000007

