module Main where

import           Control.Monad       as CM (forM, forM_, replicateM)
import qualified Data.List           as DL (intersect)

quasiSolveB :: (Int, Int) -> IO Int
quasiSolveB (n, m) = do
  contents <-
    (\strings -> do
       oneLine <- strings
       let string2Ints = fmap read . tail . words :: String -> [Int]
       return $ string2Ints oneLine) <$>
    CM.replicateM n getLine
  return $ length $ foldl1 DL.intersect contents

main = do
  ans <- getLine >>= quasiSolveB . (\x -> (head x, last x)) . fmap read . words
  putStrLn $ show ans
