import Control.Monad

ret [] l       = foldl (\acc x -> if x == 0 then acc + 1 else acc) 0 l
ret (x : xs) l =
  let 
    l' = foldl (\l y -> take (y-1) l ++ [(head $ drop (y - 1) l) - 1] ++ drop y l) l (tail x)
  in 
    ret xs l'

 
  






main = do
      [n, m] <- (map read . words) <$> getLine
      inputlist <- replicateM n ((map read . words) <$> getLine)
      putStrLn $ show $ ret inputlist $ replicate m n
