import Data.List
import Control.Monad

main = do
  [n,m] <- map read . words <$> getLine
  as <- replicateM n (tail . map read . words <$> getLine) :: IO [[Int]]
  print $ length $ filter (==n) $ map length $ group $ sort $ concat as 
