import           Control.Monad
import           Data.List

main :: IO ()
main = do
    [n, _] <- fmap (map read . words) getLine :: IO [Int]
    ass    <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    print $ solve $ map tail ass    -- あらかじめ各行の先頭は取り除いておく

-- 全ての行に含まれる料理をintersectでフィルタしてカウント
solve :: [[Int]] -> Int
solve ass = length $ foldl1 intersect ass
