import Control.Applicative

powmod _ 0 _ = 1
powmod base exponent modulus = ((if exponent `mod` 2 == 1 then base else 1) * powmod (base * base) (exponent `div` 2) modulus) `mod` modulus

main = do
  [n, k] <- map read . words <$> getLine
  print $ powmod k n (10 ^ 9 + 7)

