import Data.List

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