open System

let n = Console.ReadLine() |> int

let testimonies: (int * int) list list =
    [ for i in 1 .. n do
        let a = Console.ReadLine() |> int
        yield [ for j in 1 .. a do
                    let xy = Console.ReadLine().Split(' ') |> Array.map int
                    yield xy.[0] - 1, xy.[1] ] ]

let ans =
    let rec dfs is rest =
        match rest with
        | [] ->
            let set = Set is

            let ok =
                is
                |> List.map (fun i -> testimonies.[i])
                |> List.map (fun testimonies ->
                    testimonies
                    |> List.forall (fun testimony ->
                        let x, y = testimony
                        (y = 0 && not (set.Contains x)) || (y = 1 && set.Contains x)))
                |> List.forall (fun b -> b)

            if ok then List.length is else 0
        | i :: rest ->
            max (dfs is rest) (dfs (i :: is) rest)

    dfs [] [ 0 .. n - 1 ]

ans |> Console.WriteLine
