// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int A[15], X[15][15], Y[15][15];

int main(){
	int N; cin>>N;
	rp(i, 0, N){
		cin>>A[i];
		rp(j, 0, A[i]){ cin>>X[i][j]>>Y[i][j]; X[i][j]--; }
	}

	int ans = 0;
	for(int ok=1, bits=1; bits<1<<N; ++bits, ok=1){
		for(int i=0; i<N && ok; ++i)
			if((bits>>i)&1)
				for(int j=0; j<A[i] && ok; ++j) if(((bits>>X[i][j])&1) != Y[i][j]) ok = 0;
		if(ok) ans = max(ans, (int)bitset<16>(bits).count());
	}
	cout<< ans <<endl;
}