import Data.List
import Control.Monad.State

main = do
    [n, m] <- map read . words <$> getLine
    xss <- map (map read . tail . words) <$> sequence (replicate n getLine)
    print . fst $ runState (acnt n m xss) (replicate m 0)

fresh :: Int -> Int -> [Int] -> State [Int] Int
fresh n m xs = state $ \s ->
    let xs' = map (\x -> if x `elem` xs then 1 else 0) [1..m]
        s' = zipWith (+) xs' s
        in (length . filter (==n) $ s', s')

acnt :: Int -> Int -> [[Int]] -> State [Int] Int
acnt n m [] = fresh n m (replicate m 0)
acnt n m [xs] = fresh n m xs
acnt n m (xs:xss) = do
    acnt n m [xs]
    acnt n m xss
    s <- get
    return (length . filter (==n) $ s)
