import std.stdio, std.string, std.algorithm, std.array, std.range, std.conv,
    std.typecons, std.math, std.container, std.format;

// from https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
class UnionFind
{
public:
    long[] par;

    this(long size)
    {
        par = new long[](size);
        foreach (i; 0 .. size)
        {
            par[i] = -1;
        }
    }

    long size(long x)
    {
        return -(par[find(x)]);
    }

    long find(long x)
    {
        if (par[x] < 0)
        {
            return x;
        }
        par[x] = find(par[x]);
        return par[x];
    }

    bool is_same(long x, long y)
    {
        return find(x) == find(y);
    }

    bool unite(long x, long y)
    {
        x = find(x);
        y = find(y);

        if (x == y)
        {
            return false;
        }
        if (par[x] > par[y])
        {
            par[y] += par[x];
            par[x] = y;
        }
        else
        {
            par[x] += par[y];
            par[y] = x;
        }
        return true;
    }
}

void main(string[] args)
{
    alias T = Tuple!(int, int);
    T[][] xss = [];
    long n = readln.strip.to!long;
    foreach (i; 0 .. n)
    {
        long m = readln.strip.to!long;
        T[] xs = [];
        foreach (j; 0 .. m)
        {
            int x, y;
            readf("%d %d\n", &x, &y);
            xs ~= T(x - 1, y);
        }
        xss ~= xs;
    }

    long ans = 0;
    // 下から i bit目 が1 -> i番は正直者としてみる
    foreach (i; 0 .. (2 ^^ n))
    {
        // 矛盾している人がいたらだめ
        bool ok = true;
        check: foreach (j; 0 .. n)
        {
            if (((1 << j) & i) == 0)
            {
                continue;
            }

            foreach (xs; xss[j])
            {
                if (xs[1] == 0 && ((1 << xs[0]) & i) != 0)
                {
                    ok = false;
                    break check;
                }
                if (xs[1] == 1 && ((1 << xs[0]) & i) == 0)
                {
                    ok = false;
                    break check;
                }
            }
        }
        if (ok)
        {
            long cnt = 0;
            while (i > 0)
            {
                if ((i & 1) == 1)
                {
                    cnt++;
                }
                i = i >> 1;
            }
            ans = max(cnt, ans);
        }
    }
    writeln(ans);
}
