#include <iostream>
#include <bitset>
using namespace std;

int main() {
	int n;
	cin >> n;
	int A[15];
	int x[15][15], y[15][15];
	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];
			x[i][j]--;
		}
	}

	int ans = 0;
	for (int i = 0; i < (1<<n); i++) {
		bitset<15> t(i);
		int now = 0;
		for (int i = 0; i < n; i++) now += t[i];
		bool ok = true;
		for (int i = 0; i < n; i++) {
			if (t[i]) for (int j = 0; j < A[i]; j++) {
				if (y[i][j] == 0){
					if (t[x[i][j]] != 0) ok = false;
				} else {
					if (t[x[i][j]] != 1) ok = false;
				}

			}
		}
		if (ok) ans = max(ans, now);
	}
	cout << ans << endl;
	return 0;
}