import Control.Monad

main = do
    [n,m] <- map read . words <$> getLine
    a <- replicateM n (map read . words <$> getLine) :: IO [[Int]]
    let b = join $ map (\x -> tail x) a
    print $ sum [ isAns b i n | i<-[1..30]]

    
isAns :: [Int] -> Int -> Int -> Int
isAns b i n = let num = filter (==i) b in if length num == n then 1 else 0 
