#include<bits/stdc++.h>
using namespace std;
const int MN = 20;
using pii = pair<int,int>;
vector<pii> test[MN];
int main () {
	int n;
	scanf ("%d",&n);
	for (int i = 0; i < n; i++) {
		int len;
		scanf ("%d",&len);
		test[i].resize(len);
		for (auto &au : test[i]) scanf ("%d %d",&au.first,&au.second), --au.first;
	}
	int ans = 0;
	for (int i = 1; i < (1 << n); i++) {
		for (int j = 0; j < n; j++) if (i>>j&1) {
			for (auto &au : test[j]) {
				if (au.second == 0 && (i>>au.first&1)) goto fail;
				else if (au.second == 1 && !(i>>au.first&1)) goto fail;
			}
		}
		ans = max(ans,__builtin_popcount(i));
		fail:;
	}
	printf ("%d\n",ans);
	return 0;
}