import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

alias Appeal = Tuple!(int, "from", int, "to", bool, "isHonest");

void main() {
  auto N = readln.chomp.to!int;
  Appeal[] appeals;
  foreach(i; 0..N) {
    auto appeal_count = readln.chomp.to!int;
  
    foreach(o; 0..appeal_count) {
      auto xy = readln.split.to!(int[]);
      appeals ~= Appeal(i, xy[0] - 1, xy[1] == 1);
    }
  }

  int solve() {
    foreach(i; N.iota(0, -1)) {
      pattern: foreach(c; N.iota.array.combinations(i)) {
        bool[] honests = new bool[N];
        foreach(n; c) honests[n] = true;
        foreach(ap; appeals.filter!(ap => honests[ap.from] == true)) {
          if (ap.isHonest != honests[ap.to]) break pattern;
        }
        return i;
      }
    }
    return 0;
  }

  solve().writeln;
}
