import core.bitop, std.bitmanip;
import core.checkedint;
import std.algorithm, std.functional, std.meta;
import std.array, std.container;
import std.bigint;
import std.conv;
import std.math, std.numeric;
import std.range, std.range.interfaces;
import std.stdio, std.string;
import std.typecons;

void main()
{
    int n;
    readf("%s", &n);
    readln;
    
    alias tmny = Tuple!(int, int);
    auto t = new tmny[][] (n);
    foreach (i; 0 .. n) {
        int a;
        readf("%s", &a);
        readln;
        
        foreach (_; 0 .. a) {
            int x, y;
            readf("%s %s", &x, &y);
            readln;
            
            t[i] ~= tmny(x, y);
        }
    }
    
    int ans = 0;
    
    bool isHonest(int v, int bt) { return ((1 << v) & bt) > 0; }
    
    outer: foreach (bt; 1 .. (1 << n)) {
        foreach (i; 0 .. n) {
            if (!isHonest(i, bt)) { continue; }
            
            foreach (ts; t[i]) {
                if (isHonest(ts[0] - 1, bt) != ts[1]) {
                    continue outer;
                }
            }
        }
        
        int cur = bt.popcnt;
        if (cur > ans) { ans = cur; }
    }
    
    ans.writeln;
}