#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main() {
  int n;
  cin>>n;
  vector<P> v[20];
  rep(i,n) {
    int a;
    cin>>a;
    rep(j,a) {
      int x,y;
      cin>>x>>y;
      x--;
      v[i].push_back({x,y});
    }
  }
  int ans=0;
  rep(bit,1<<n) {
    bool flag=true;
    rep(i,n) {
      if(bit&(1<<i)) {
	rep(j,v[i].size()) {
	  if((bit>>v[i][j].first&1)!=v[i][j].second) {
	    flag=false;
	  }
	}
      }
    }
    int cnt=0;
    if(flag) {
      rep(i,n) {
	if(bit&(1<<i)) cnt++;
      }
    }
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}



