-- ナニソレイミワカンナイ import Control.Monad mo = 1000000000 nCr :: Integer -> Integer -> Integer nCr n k | n < k = 1 | otherwise = product [1..n] `div` product [1..k] `div` product [1..(n-k)] main = do n <- readLn m <- readLn let n' = n `mod` (1000 * m) `div` 1000 in print (nCr m n' `mod` mo)