/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/* libnum {{{*/
void amax(N, Args...)(ref N x, Args y) {
  x = x.max(y);
}
void amin(N, Args...)(ref N x, Args y) {
  x = x.min(y);
}
auto maxE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amax(y);
  return x;
}
auto minE(R)(R r) if (isInputRange!R) {
  ElementType!R x = r.front;
  r.popFront();
  foreach (y; r) x.amin(y);
  return x;
}
/*}}}*/

/+---test
3
1
2 1
1
1 1
1
2 0
---+/
/+---test
3
2
2 1
3 0
2
3 1
1 0
2
1 1
2 0
---+/
/+---test
2
1
2 0
1
1 0
---+/
/+---test
15
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;

  long[][][] testimonies;
  testimonies.length = N;

  foreach (ref tests; testimonies) {
    const A = readln.chomp.to!long;
    tests.length = A;
    foreach (ref t; tests) {
      t.length = 2;
      readf(" %d %d ", &t[0], &t[1]);
      --t[0];
    }
  }

  long ans;
SKIP: foreach (ushort honest; 0..2.pow(N).to!ushort) {
    foreach (i; 0..N) {
      if ((honest >> i & 1) == 0) continue;
      foreach (test; testimonies[i]) {
        if ((honest >> test[0] & 1) != test[1]) continue SKIP;
      }
    }

    long cnt;
    foreach (i; 0..N) {
      if (honest >> i & 1) ++cnt;
    }
    ans.amax(cnt);
  }
  ans.writeln;
}
