import Control.Monad
import Control.Applicative
import Data.List


getBysplit = map read . words <$> getLine

getList :: IO [Int]
getList = do
  (k:xs) <- getBysplit :: IO [Int]
  return xs

main :: IO()
main = do
  [n, m] <- getBysplit :: IO [Int]
  lst <- replicateM n getList
  print $ solve [1..m] lst


solve :: [Int] -> [[Int]] -> Int
solve list lst = sum [ v | x <- list, let v = f x lst]
    where
      f :: Int -> [[Int]] -> Int
      f x lst = if (all (==True) . map (elem x)) lst
                  then 1
                  else 0
