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