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

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "x", long, "y");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    auto status = new long[][](n, n);
    foreach (ref e; status)
        e[] = -1;

    foreach (i; iota(n))
    {
        auto a = lread();
        foreach (_; iota(a))
        {
            long x, y;
            scan(x, y);
            status[i][x - 1] = y;
        }
    }
    // status.each!(x => x.writeln());
    long ans;
    outer: foreach (s; iota(0, 1 << n))
    {
        auto p = new long[](n);
        p[] = -1;
        foreach (loc; iota(n))
        {
            if (s & (1 << loc))
            {
                bool t = true;
                t &= (p[loc] != 0);
                p[loc] = 1;
                foreach (u; iota(n))
                {
                    if (p[u] == -1)
                        p[u] = status[loc][u];
                    else if (status[loc][u] != -1 && p[u] != status[loc][u])
                        t = false;
                }
                // writef("%b, %s ", s, loc);
                // p.writeln(" ", t);
                if (!t)
                    continue outer;
            }
            else
            {
                // writef("%b, %s ", s, loc);
                // p[loc].writeln("= p[loc]");
                if (p[loc] == 1)
                    continue outer;
                p[loc] = 0;
            }
        }
        ans = max(ans, popcnt(s));
        // ans.writeln(" = ans");
    }
    ans.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
