import Control.Monad
import qualified Data.IntSet as S

main :: IO ()
main = do
  [n, _] <- readInts
  sets <- replicateM n readFavo
  print $ solve sets

readInts :: IO [Int]
readInts =map read . words <$> getLine

readFavo :: IO S.IntSet
readFavo = do
  (_ : as) <- readInts
  return $ S.fromList as

solve :: [S.IntSet] -> Int
solve [x] = S.size x
solve (x:y:zs) = solve $ (x `S.intersection` y) : zs