import           Control.Monad
import           Data.List

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  as <- replicateM n $ tail . map read . words <$> getLine :: IO [[Int]]
  print
    $ length . filter (== True) . map and . transpose
    $ map (\a -> [x `elem` a | x <- [1 .. m]]) as