import Control.Monad
import Data.List
main = do
  [n,m] <- map read . words <$> getLine
  k <- replicateM n $ map read . words <$> getLine
  let l = map tail k
  print $ length $ foldl intersect [1..m] l