#include <stdio.h>
int n, m, l, g, e;
int a[15], b[15];
int x[15][15], y[15][15];
int ans;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
		for (int j = 0; j < a[i]; j++) {
			scanf("%d%d", x[i] + j, y[i] + j);
			x[i][j]--;
		}
	}
	m = 1;
	for (int i = 0; i < n; i++) {
		m *= 2;
	}
	for (int i = 0; i < m; i++) {
		l = i;
		g = 1;
		e = 0;
		for (int j = 0; j < n; j++) {
			b[j] = l % 2;
			l /= 2;
			e += b[j];
		}
		for (int j = 0; j < n; j++) {
			if (b[j]) {
				for (int k = 0; k < a[j]; k++) {
					if (b[x[j][k]] != y[j][k]) {
						g = 0;
					}
				}
			}
		}
		if (g) {
			if (ans < e)ans = e;
		}
	}
	printf("%d\n", ans);
}

#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
ll N;
  cin>>N;
  vector<vector<pair<ll,ll>>> vec(N,vector<pair<ll,ll>>(0));
  for(ll i=0;i<N;i++) {
ll A;
    cin>>A;
    for(ll j=0;j<A;j++) {
ll x,y;
      cin>>x>>y;
      vec[x-1].push_back(make_pair(i+1,y));
    }
  }
  
  
  ll ans=0;
  for(ll tmp=0;tmp<(1<<N);tmp++) {
bitset<15> S(tmp);
    bool a=true;
    
    for(ll i=0;i<N;i++) {
      ll k;
      if(S.test(i)) {
k=1;
      }
      else {
        k=0;
      }
for(auto x:vec[i]) {
  if(S.test(x.first-1)) {
  if(x.second!=k) {
a=false;
  }
}
      
}
    }

    if(a) {
      ll sum=S.count();
ans=max(ans,sum);
    }
  }
  
  
  
  
  cout<<ans<<endl;
}
    
    
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  