#include<bits/stdc++.h>
using namespace std;

int main(){
	int n;
	cin>>n;
	int kind[16];
	int unkind[16];
	
	for(int i=0; i<n; i++){
		int kind_p = 0;
		int unkind_p = 0;
		int t;
		cin>>t;
		while(t--){
			int a,b;
			cin>>a>>b;
			if(b) kind_p |=(1<<--a);
			else unkind_p|=(1<<--a);
		}
		kind[i] = kind_p;
		unkind[i] = unkind_p;
	}
	int maxpeople = 0;
	for(int i=0; i<(1<<n); i++){
		int totalkind = 0;
		int totalunkind = 0;
		for(int j=0; j<n; j++){
			if(i&(1<<j)){
				totalkind|=kind[j];
				totalunkind|=unkind[j];
			}
		}
		bool possible = true;
		for(int j=0; j<n; j++){
			if(totalkind&(1<<j) && (i&(1<<j))==0) possible = false;
			if(totalunkind&(1<<j) && i&(1<<j)) possible = false;
		}
		
		if(possible) maxpeople = max(maxpeople,__builtin_popcount(i));
	}
	//for(int i=0; i<n; i++) cout<<kind[i]<<" ";
	cout<<maxpeople;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int n;
  cin >> n;
  vector<vector<pair<int, int> > > data(n);
  for (int i = 0; i < n; i++) {
    int sz;
    cin >> sz;
    data[i].resize(sz);
    for (int j = 0; j < sz; j++) {
      cin >> data[i][j].first >> data[i][j].second;
      data[i][j].first--;
    }
  }
  int mask = (1 << n) - 1;
  while (mask) {
    int ppl = mask, i = n - 1;
    bool poss = true;
    while (ppl) {
      if (ppl & 1) {
        for (pair<int, int> p : data[i]) {
          int id = n - 1 - p.first;
          if (p.second && !((1 << id)&mask) || !p.second && (1 << id)&mask)
            poss = false;
        }
      }
      ppl /= 2;
      i--;
    }
    if (poss)
      break;
    mask--;
  }
  cout << __builtin_popcount(mask);
  return 0;
}