import Control.Monad
import Data.List

solve :: [[Int]] -> Int
solve [_:x]              = length x
solve [_:x1,_:x2]        = length $ intersect x1 x2
solve (x1all@(_:x1):x2all@(_:x2):xs)
  | solve [x1all,x2all] == 0 = 0
  | otherwise                = solve $ (intersect x1 x2):xs

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