import qualified GHC.Integer.GMP.Internals as GMP modulus :: Int modulus = 1000000007 {-# INLINE modulus #-} fi :: Int -> Integer fi = fromIntegral {-# INLINE fi #-} fI :: Integer -> Int fI = fromInteger {-# INLINE fI #-} powModInt :: Int -> Int -> Int powModInt a b = fI $ GMP.powModInteger (fi a) (fi b) (fi modulus) {-# INLINE powModInt #-} main :: IO () main = do [p, k] <- map (read :: String -> Int) . words <$> getLine let t1 = powModInt 10 (p - 1) t2 = (t1 + modulus - 1) `mod` modulus t3 = t2 * powModInt p (modulus - 2) `mod` modulus if k == 0 then print $ (t3 + 1) `mod` modulus else print t3