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

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

bool check(BITS &bits){
	rp(i, 0, N)
		if(bits[N-1-i])
			rp(j, 0, A[i]) if(bits[N-1-X[i][j]] != Y[i][j]) return false;
	return true;
}

int main(){
	cin>>N;
	rp(i, 0, N){ cin>>A[i]; rp(j, 0, A[i]){ cin>>X[i][j]>>Y[i][j]; X[i][j]--; } }
	for(int bits=(1<<N)-1; bits>0; --bits){
		BITS b(bits); if(check(b)){ cout<<b.count()<<endl; return 0; }
	}
	puts("0");
}