let () =
    let main () =
        let n = int_of_string (read_line ()) in
        let xy = Array.make_matrix n n (-1) in
        for i = 0 to n - 1 do
            let a1 = int_of_string (read_line ()) in
            for j = 0 to a1 - 1 do
                Scanf.sscanf (read_line ()) "%d %d" (fun x y -> xy.(i).(x - 1) <- y)
            done
        done;
        let bits a = 
            let rec loop a acc =
                if a = 0 then acc else loop (a lsr 1) (acc + (a land 1))
            in
            loop a 0
        in
        let judge i =
            let judge2 t =
                if i land (1 lsl t) = 0 then true else (
                    let rec loop2 k =
                        if k = n then true else (
                            if xy.(t).(k) < 0 then loop2 (k + 1) else (
                                if (xy.(t).(k) = 0 && (i land (1 lsl k) = 0)) ||
                                   (xy.(t).(k) = 1 && (i land (1 lsl k) != 0)) then loop2 (k + 1)
                                else false
                            )
                        )
                    in
                    loop2 0
                )
            in
            let rec loop s =
                if s = n then true else (
                    if judge2 s then loop (s + 1) else false
                )
            in
            loop 0
        in
        let maxn = 1 lsl n in
        let rec loop i acc =
            if i = maxn then acc else
                let acc = if judge i then max acc (bits i) else acc in
                loop (i + 1) acc
        in
        let r = loop 0 0 in
        Printf.printf "%d\n" r
    in
    main ()