module Main where

import qualified Data.List as DL
import qualified Control.Monad as CM

readInt :: String -> Int
readInt = read

solveB :: IO ()
solveB = do
  [n, m] <- fmap read . words <$> getLine
  set <- foldl1 DL.intersect <$> CM.replicateM n (fmap readInt . tail . words <$> getLine)
  print $ length set
  
main = solveB