import qualified Data.Vector as V
import Control.Monad
import Data.Bits

type Hint = V.Vector (Int, Int)
type Status = V.Vector (Bool, Int)

toBitV :: Int -> Int -> V.Vector Int
toBitV n l
    | l == 0 = V.empty 
    | otherwise = V.snoc (toBitV (shiftR n 1) (l - 1)) (n .&. 1)

solve :: V.Vector Hint -> Int -> Int -> Int
solve xss n i
  | cond = len
  | otherwise = 0
  where
    len = V.length $ V.filter (==1) $ V.map snd res
    cond = V.and $ V.map fst res
    res = step xss' status

    bs = toBitV i n
    status = V.zip (V.replicate n True) bs
    xss' = V.zip bs xss

    step :: V.Vector (Int, Hint) -> Status -> Status
    step xss status 
      | V.null xss = status
      | bit == 0 = step tss status -- 0と仮定しているなら無視
      | bit == 1 = step tss status'-- 1と仮定しているなら検証
        where
          (bit, hint) = V.head xss
          status' = V.accumulate step' status hint
          step' (branch, b) x = (branch && (b==x),b)
          tss = V.tail xss

main = do
  n <- readLn :: IO Int
  vec <- V.replicateM n $ do
    a <- readLn :: IO Int
    xs <- V.replicateM a $ do
      [x,y] <- map read . words <$> getLine :: IO [Int]
      return (x-1,y)
    return xs
  let res = [solve vec n i | i <- [0..2^n-1]] 
  print $ maximum res
