#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
bool operator<(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first < b.first;
}
int A[20];
int x[20][20], y[20][20];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    for (int j = 0; j < A[i]; j++) {
      cin >> x[i][j] >> y[i][j];
    }
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++) {
    map<int, bool> mp;
    int ct = 0;
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        mp[i] = true;
        ct++;
      } else {
        mp[i] = false;
      }
    }
    bool ok = true;
    for (int i = 0; i < N; i++) {
      if (mp[i]) {
        for (int j = 0; j < A[i]; j++) {
          if ((y[i][j] == 1 && !mp[x[i][j]]) || (y[i][j] == 0 && mp[x[i][j]]))
            ok = false;
        }
      }
    }
    if (ok) ans = max(ans, ct);
  }
  cout << ans << endl;
  return 0;
}
