import Control.Monad
import Data.List

solve :: [[Int]] -> Int
solve [_:x] = length x
solve [_:x1,_:x2] = length $ intersect x1 x2
solve ((_:x1):(_:x2):xs) = solve $ (intersect x1 x2):xs

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