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

enum MAX = 1_000_100;
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias Pass = Tuple!(long, "x", long, "y");

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

    foreach (i; iota(n))
    {
        auto a = lread();
        foreach (j; iota(a))
        {
            long x, y;
            scan(x, y);
            table[i][x - 1] = y;
        }
    }
    long max_cnt;
    foreach (i; iota(1 << n))
    {
        long cnt;
        foreach (row; iota(n))
        {
            bool honest, unkind, conflict;
            foreach (col; iota(n))
            {
                if (table[col][row] < 0)
                    continue;

                long tmp;
                if ((i >> col & 1))
                    tmp = table[col][row];
                else
                    tmp = !table[col][row];

                if (tmp)
                    honest = true;
                else
                    unkind = true;

                if (honest & unkind)
                {
                    conflict = true;
                    break;
                }
            }
            if (conflict)
            {
                cnt = 0;
                break;
            }
            else if (honest)
                cnt++;
        }
        max_cnt = max(cnt, max_cnt);
    }
    max_cnt.writeln();
}

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

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