main = do
    [n, m] <- map read . words <$> getLine
    xs <- solve m n
    print . length . filter (==n) $ xs

solve :: Int -> Int -> IO [Int]
solve m 0 = return $ replicate m 0
solve m n = do
    k:as <- map read . words <$> getLine
    let xs = map (\i -> if i `elem` as then 1 else 0) [1..m]
    ys <- solve m (n - 1)
    let zs = zipWith (+) xs ys
    return zs
