#include <bits/stdc++.h>
using namespace std;

int main() {
  int n; cin >> n;
	vector<vector<int>> A(n, vector<int>(n, -1));
	for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    while (a--) {
      int x, y; cin >> x >> y;
      --x;
      A[i][x] = y;
    }
	}
  int ans = 0;
  for (int S = 0; S < (1<<n); ++S) {
    bool test = true;
    for (int i = 0; i < n; ++i) if (S&1<<i) {
      for (int j = 0; j < n; ++j) {
        test &= A[i][j] == -1 or A[i][j] == (S>>j&1);
      }
    }
    if (test) ans = max<int>(ans, __builtin_popcount(S));
  }
  cout << ans << '\n';
}
