import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto N = readln.chomp.to!int;
    auto A = new int[][](N, N);
    foreach (i; 0..N) A[i][] = -1;

    foreach (i; 0..N) {
        int a = readln.chomp.to!int;
        foreach (j; 0..a) {
            auto s = readln.split.map!(to!int);
            auto x = s[0] - 1;
            auto y = s[1];
            A[i][x] = y;
        }
    }

    int ans = 0;

    foreach (mask; 0..1<<N) {
        bool ok = true;
        foreach (i; 0..N) {
            if (mask & (1 << i)) {
                foreach (j, a; A[i]) {
                    if (a == 0) {
                        if (mask & (1 << j)) {
                            ok = false;
                            break;
                        }
                    } else if (a == 1) {
                        if (!(mask & (1 << j))) {
                            ok = false;
                            break;
                        }
                    }
                }
                if (!ok) {
                    break;
                }
            }
        }
        if (ok) ans = max(ans, mask.popcnt);
    }

    ans.writeln;
}