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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int N;
    scan(N);
    auto x = new int[][](N, 0);
    auto y = new int[][](N, 0);
    foreach (i ; 0 .. N) {
        int Ai;
        scan(Ai);
        while (Ai--) {
            int xi, yi;
            scan(xi, yi);
            xi--;
            if (yi) {
                x[i] ~= xi;
            }
            else {
                y[i] ~= xi;
            }
        }
    }

    int ans;

    foreach (s ; 0 .. (1 << N)) {
        bool ok = true;

        foreach (j ; 0 .. N) if (s & (1 << j)) {
            foreach (xk ; x[j]) {
                if (!(s & (1 << xk))) {
                    ok = false;
                }
            }
            foreach (yk ; y[j]) {
                if (s & (1 << yk)) {
                    ok = false;
                }
            }
        }

        if (ok) ans = max(ans, s.popcnt);
    }

    writeln(ans);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}
