import Control.Monad
import Control.Monad.State
import Debug.Trace
 
main = do
    [n,m] <- map read . words <$> getLine
    ass <- replicateM n (map read . tail . words <$> getLine) :: IO [[Int]]
    print . fst $ runState (solve n m ass) (replicate m 0) 
 
oneHot :: Int -> [Int] -> [Int]
oneHot m s = map (\x -> if x `elem` s then 1 else 0) [1..m]

reflesh :: Int -> Int-> [Int] -> State [Int] Int
reflesh n m as = state $ \s -> 
        let s' = zipWith (+) s $ oneHot m as
            a' = length $ filter (==n) s'
        in (a',s')

solve :: Int -> Int -> [[Int]] -> State [Int] Int
solve n m [] = do
    reflesh n m (replicate m 0) 
solve n m (as:ass) = do
    reflesh n m as
    solve n m ass