import           Control.Monad

main :: IO ()
main = do
    [n, m] <- fmap (map read . words) getLine :: IO [Int]
    ass    <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    print $ solve n m ass

solve :: Int -> Int -> [[Int]] -> Int
solve n m ass = length $ filter (judge n ass) [1 .. m]

judge :: Int -> [[Int]] -> Int -> Bool
judge n ass k = n == length (filter (\v -> k `elem` (tail v)) ass)
