{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import Data.Char
import Data.Bits

main :: IO ()
main = do
  n <- readLn :: IO Int
  xys <- replicateM n readxy :: IO [[[Int]]]
  print $ solve n xys

solve :: Int -> [[[Int]]] -> Int
solve n xys = if null ans then 0 else (maximum ans)
  where
    ans = map sum . filter isPossible $ candidates
    candidates = candidate n
    isPossible candidate = go candidate xys
      where
        go :: [Int] -> [[[Int]]] -> Bool
        go [] _ = True
        go _ [] = True
        go (c:cs) (xy:xys)
          | isOK = go cs xys
          | otherwise = False
          where
            f x y = (c == 1) `xor` (candidate!!(x-1) /= y)
            isOK = foldl' g True xy
            g acc (x:y:_) = acc && (f x y)

readxy = do
  a <- readLn :: IO Int
  xy <- replicateM a $ map read . words <$> getLine :: IO [[Int]]
  return xy


candidate n = replicateM n [0, 1]