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 = 1_000_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", long, "cost");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    auto n = lread();
    long ans;
    auto infomat = new long[][](n, n);
    foreach (ref e; infomat)
        e[] = -1;
    foreach (i; iota(n))
    {
        auto a = lread();
        foreach (_; iota(a))
        {
            long x, y;
            scan(x, y);
            infomat[i][x - 1] = y;
        }
    }
    // 右から1スタートで扱う
    foreach (mask; iota(1 << n))
    {
        auto state = new long[](n);
        bool contradict;
        // writefln("%02b", mask);
        foreach (shift; iota(n))
            state[shift] = (mask & (1 << shift)) ? 1 : 0;
        foreach (i; iota(n))
        {
            if (state[i])
            {
                foreach (j; iota(n))
                {
                    if (infomat[i][j] == -1)
                        continue;

                    contradict |= (state[j] != infomat[i][j]);
                }
            }
        }
        if (!contradict)
            ans = max(mask.popcnt(), 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;
    }
}
