import Data.List
main = do
  [n,k] <- map (read::String->Int) . words <$> getLine
  s <- map (map (read::String->Int)) . map words . lines <$> getContents
  print $ length $ foldl1 intersect [[1..n]\\x | (i, x) <- zip [0..] s, odd i]