import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import core.bitop;

struct P {
  int honest;
  int unkind;
}

void main() {
  int n;
  readf (" %d", &n);
  auto h = new int[n];
  auto u = new int[n];
  foreach (i; 0 .. n) {
    int k;
    readf (" %d", &k);
    while (--k >= 0) {
      int x, y;
      readf (" %d %d", &x, &y);
      --x;
      if (y == 1) {
        h[i] |= 1 << x;
      } else {
        u[i] |= 1 << x;
      }
    }
  }
  int res;
  int all = (1 << n) - 1;
  foreach (i; 0 .. 1 << n) {
    bool ok = true;
    int ii = all ^ i;
    foreach (j; 0 .. n) {
      if ((1 << j) & i) {
        if ((h[j] & i) != h[j]) {
          ok = false;
          break;
        }
        if ((u[j] & ii) != u[j]) {
          ok = false;
          break;
        }
      }
    }
    if (ok) {
      debug stderr.writeln (i);
      res = max (res, popcnt (i));
    }
  }
  writeln (res);
}

