import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

powMod::Integer->Integer->Integer->Integer
powMod a d n= fun a d where
    fun a 1 = mod a n
    fun a 2 = mod (a^2) n
    fun a d = let
            p=fun (mod (a^2) n) (div d 2)
            q=if odd d then mod (a*p) n else p
          in mod q n

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