import Control.Monad
import Data.List

main = do
  [n, m] <- map read . words <$> getLine
  xs <- replicateM n (map read . words <$> getLine)
  let a = func $ group $ sort $ concat $ map tail xs
  print $ length $ filter (==n) a
  
func :: [[Int]] -> [Int]
func [] = []
func (x: xs) = length x : func xs