import Control.Monad
import Data.List

solve :: [[Int]] -> [Int]
solve [] = []
solve ((k:as):ass) = as ++ solve ass

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  as <- replicateM n $ map read . words <$> getLine
  print . length . filter (==n) . map length . group . sort $ solve as