[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f

let rec f n xss =
    if n = 0 then
        xss
    else
        let s1 = List.map (fun xs -> 1 :: xs) xss
        let s2 = List.map (fun xs -> 0 :: xs) xss
        f (n - 1) (s1 @ s2)

[<EntryPoint>]
let main _ =
    let N = read int
    let PSS =
        [|
            for i in 1 .. N do
                let A = read int
                Array.init A (fun _ -> reads int)
        |]

    let xss = f N [[]]

    let test xs =
        let xs = Array.ofList xs
        let mutable b = true
        for i, ps in Seq.zip [0 .. N - 1] PSS do
            if b && xs.[i] = 1 then
                for [|x; y|] in ps do
                    if xs.[x-1] <> y then
                        b <- false
        b

    List.filter test xss
    |> List.map (List.sum)
    |> List.max
    |> printfn "%i"

    0