import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
  [n, m] <- f
  solve n <$> replicateM n (tail <$> f) >>= print
  where
    f = map read <$> words <$> getLine

solve :: Int -> [[Int]] -> Int
solve n = length . filter ((== n) . length) . group . sort . concat
