-- 全ての受け取った値を全てconcat, sort, groupByして，大きさがNのリスト要素を返す

import Control.Applicative
import Control.Monad as M
import Data.List

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  likes <- M.replicateM n (map read .words <$> getLine)
  putStrLn $ show (solve n (map (\(x:xs) -> xs) likes))

solve :: Int -> [[Int]] -> Int
solve n = sum . map (\xs -> if length xs == n then 1 else 0) . group . sort . concat
