import Control.Monad
import Data.List
main = do
  n <- read <$> getLine
  v <- 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 (o v) (subsequences [1..n])
o s k = and [(y == 0) /= (x `elem` k) | i <- k,(x,y) <- s !! (i-1)]
