import Control.Monad
import Data.List

solve :: [[Int]] -> Int
solve list = length $ foldr1 intersect $ map tail list

main :: IO ()
main = do
  [count, _] <- map read . words <$> getLine
  lines <- replicateM count $ map read . words <$> getLine
  print $ solve lines