import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
toTuple (x : y : _) = (x, y)

main = do
    n <- getInt
    xyss <- replicateM n $ do
        a <- getInt
        xys <- map toTuple <$> replicateM a getIntList
        return xys
    let bss = sequence $ replicate n [False, True]
    print . maximum $ map (length . filter id) [bs | bs <- bss, and (map (check bs) (zip bs xyss)) ]

check bs (b, xys) | b = and $ map (\(x, y) -> bs !! (x - 1) == (y == 1)) xys
                  | otherwise = True