import Control.Monad

main = do
    [n, m] <- fmap read <$> words <$> getLine
    ka <- forM [1..n] $ \i -> do
        (k : a) <- fmap read <$> words <$> getLine
        return (k, a)
    putStrLn $ show $ solve n m ka

solve :: Int -> Int -> [(Int, [Int])] -> Int
solve n m ka = length $ filter (== n) $ map count [1 .. m]
  where
    count f = length $ filter (any (== f)) $ map snd ka