{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -O3 -fexpose-all-unfoldings -fdicts-cheap -fdicts-cheap #-}

import Data.List (delete)

zipn xs = sum (zipWith (*) xs [1..10])

length' :: [a] -> Int
length' = len 0
  where
    len n [] = n
    len n (_:l) = seq n (len (n+1) l)

nAndS [n ,s]
  | zipn [(10-n)..9] <  s = "0"
  | zipn [(10-n)..9] == s = "1"
  | zipn [0..(n-1)]  >  s = "0"
  | zipn [0..(n-1)]  == s = "1"
  | otherwise             = nAndS'[n ,s]

nAndS' :: [Int] -> String
nAndS' [n, s] = show $ length' [xs | xs <- (perm [0..9] n)
                    ,zipn xs == s]

perm :: [Int] -> Int -> [[Int]]
perm xs n = [x:ys | x <- xs
                  , ys <- (if  (n > 1) then perm (delete x xs) (n - 1) else [[]])]

main = do
  s' <- getContents
  let s = map (map read) $ map words $ lines s'
  putStr $ unlines $ map nAndS s