#include <bits/stdc++.h>
using namespace std;
const long long mod = (1e+9) + 7;
const long long inf = 1e+16;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  vector<long long> a(n);
  vector<vector<long long> > y(n, vector<long long>(n, -1));
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    for (long long j = 0; j < a[i]; j++) {
      long long x;
      cin >> x;
      x--;
      cin >> y[i][x];
    }
  }
  long long res = 0;
  for (long long i = 0; i < (1 << n); i++) {
    bool flag = true;
    for (long long j = 0; j < n; j++) {
      for (long long k = 0; k < n; k++)
        if (y[j][k] != -1 && (i >> k) != (!((i >> j) ^ y[j][k]))) flag = false;
    }
    if (flag) {
      long long cnt = 0;
      for (long long j = 0; j < n; j++) cnt += ((i >> j) & 1);
      res = max(res, cnt);
    }
  }
  cout << res << endl;
}
