#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;

int main(){
  int i,j,k,l,cnt=0;
  int n;
  cin>>n;
  int a[n];
  int x[n+1][n+1],y[n+1][n+1];
  for(i=1;i<=n;i++){
    cin>>a[i];
    for(j=1;j<=a[i];j++)cin>>x[i][j]>>y[i][j];
  }
  int p[n+1];
  int ma=0;
  int b=(int)round(pow(2,n));
  for(i=1;i<b;i++){
    cnt=0;
    for(j=0;j<n;j++){
      p[j+1]=(i/(int)round(pow(2,j)))%2;
      if(p[j+1]==1)cnt++;
    }
    for(k=1;k<=n;k++){
      for(l=1;l<=a[k];l++){
        if(p[k]==1 && (y[k][l]!=p[x[k][l]])){
          cnt=0;
          break;
        }
      }
    }
    ma=max(cnt,ma);
  }
  cout<<ma;
}