import Control.Monad (replicateM)
import Data.List (sort, group)

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