import Control.Monad
main = do
  n <- read <$> getLine
  xy <- forM [1..n] $ \i -> do
    a <- read <$> getLine
    forM [1..a] $ \j -> do
      [x,y] <- map read . words <$> getLine
      return (x,y)
  print $ maximum $ length <$> filter (ok xy) (powerset [1..n])
powerset = filterM (const [True,False])
ok xys kinds = and [(y == 0) /= (x `elem` kinds) | i <- kinds,(x,y) <- xys !! (i-1)]