#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<vector<pair<int, int>>> testify;
  for (int i = 0; i < (int)(n); i++) {
    cin >> a[i];
    vector<pair<int, int>> temp;
    for (int j = 0; j < (int)(a[i]); j++) {
      int c, b;
      cin >> c >> b;
      c--;
      temp.push_back(pair<int, int>(c, b));
    }
    testify.push_back(temp);
  }
  int ma = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    bool ok = true;
    int cnt = 0;
    for (int i = 0; i < (int)(n); i++) {
      if (bit & (1 << i)) {
        cnt++;
        for (int j = 0; j < (int)(a[i]); j++) {
          int to = testify[i][j].first;
          int honest = testify[i][j].second;
          if (((bit >> to) & 1) != honest) {
            ok = false;
            goto check;
          }
        }
      }
    }
  check:
    if (ok) ma = max(ma, cnt);
  }
  cout << ma << endl;
  return 0;
}
