import Data.List (intersect)

main :: IO ()
main = do
  [_, m] <- map read . words <$> getLine
  aijs <- map (map read . tail . words) . lines <$> getContents
  print $ length $ foldr intersect [1..m] aijs
