import Control.Monad
import Data.List
 
readInt = readLn :: IO Int
readInts = map read . words <$> getLine :: IO [Int]
readNInts = flip replicateM readInts

main :: IO ()
main = do
  [n, m] <- readInts
  a <- map tail <$> readNInts n
  print . length $ foldr1 intersect a