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) 

acnt :: Int -> Int -> [[Int]] -> State [Int] Int
-- acnt n m [] = state $ \s -> (length . filter (==n) $ s, s)
acnt n m [] = length . filter (==n) <$> get
--acnt n m (xs:xss) = state $ \s -> let xs' = map (\x -> if x `elem` xs then 1 else 0) [1..m]
--                                      (_, xs'') = runState (acnt n m xss) s
--                                      s' = zipWith (+) xs' xs''
--                                      in (length . filter (==n) $ s', s')
acnt n m (xs:xss) = do
    acnt n m xss
    s <- get
    let xs' = map (\x -> if x `elem` xs then 1 else 0) [1..m]
        s' = zipWith (+) xs' s
    put s'
    return (length . filter (==n) $ s')
