//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1 << 4;

int T[maxN][maxN];

int main() {
	int n; cin >> n;
	for(int i = 0; i < n; i++) {
		int A; cin >> A;
		for(int j = 0; j < A; j++) {
			int x, y; cin >> x >> y;
			x--;
			if(y) T[i][x] = 1;
			else  T[i][x] = -1;
		}
	}
	int r = 0;
	for(int msk = 0; msk < (1 << n); msk++) {
		bool valid = true;
		for(int bit = 0; bit < n; bit++) if(msk & (1 << bit))
			for(int i = 0; i < n; i++) {
				if(T[bit][i] == 1 && !(msk & (1 << i))) valid = false;
				if(T[bit][i] == -1 && (msk & (1 << i))) valid = false;
			}
		if(valid) r = max(r, __builtin_popcount(msk));
	}
	cout << r;
}
