import Data.List
main = do
  n <- read <$> getLine
  xy <- sequence $ replicate n $ do
        a <- read <$> getLine
        sequence $ replicate a $ do
          [x,y] <- map read . words <$> getLine
          return (x,y)
  print $ maximum $ length <$> filter (ok xy) (subsequences [1..n])
ok xys kinds = and [(y == 0) /= (x `elem` kinds) | i <- kinds,(x,y) <- xys !! (i-1)]