import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : p : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  cs <- getLine :: IO String
  let
    candidates :: [Integer]
    candidates = map read . concat . uncurry (:) . foldr step ([], []) $ cs
      where
        step :: Char -> ([String], [[String]]) -> ([String], [[String]])
        step c (css, csss) = (map (c :) ("" : css), css : csss)
  print . length . filter ((== 0) . (`mod` toInteger p)) $ candidates

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
