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

int main() {
int N;
  cin >> N;
 vector<vector<int>> tof(16, vector<int>(16));
  int a,x,y;
  for(int i = 1; i <= N; i++){
  	cin >> a;
    for(int j = 0; j < a; j++){
    	cin >> x >> y;
      if(y == 0){
      	tof[i][x] = 2;
      }
      else
      tof[i][x] = y;
    }
  }
 /* for(int i = 1; i <= N; i++){
  	for(int j = 1; j <= N; j++){
    	cout << tof[i][j] << " ";
    }
    cout << endl;
  }*/
  int kouho,count;
  priority_queue <int> ans;
  vector<int> joutai(16);
  
  for(int i1 = 1; i1 <= 2; i1++){
    joutai[1]= i1;
  	for(int i2 = 1; i2 <= 2; i2++){
      joutai[2]=i2;
    	for(int i3 = 1; i3 <= 2; i3++){
          joutai[3]=i3;
        	for(int i4 = 1; i4<= 2; i4++){
              joutai[4]=i4;
            	for(int i5 = 1; i5 <= 2; i5++){
                  joutai[5]=i5;
                	for(int i6 = 1; i6 <= 2; i6++){
                      joutai[6]= i6;
                    	for(int i7 = 1; i7 <= 2; i7++){
                          joutai[7]=i7;
                        	for(int i8 = 1; i8 <= 2; i8++){
                              joutai[8]=i8;
                        		for(int i9 = 1; i9 <= 2; i9++){
                                  joutai[9]=i9;
                            		for(int i10 = 1; i10 <= 2; i10++){
                                      joutai[10]=i10;
                                    	for(int i11 = 1; i11 <= 2; i11++){
                                          joutai[11]=i11;
                                        	for(int i12 = 1; i12 <= 2; i12++){
                                              joutai[12]=i12;
                                            	for(int i13 = 1; i13 <= 2; i13++){
                                                  joutai[13]=i13;
                                                	for(int i14 = 1; i14 <= 2; i14++){
                                                      joutai[14]=i14;
                                                    	for(int i15 = 1; i15 <= 2; i15++){
                                                          joutai[15]=i15;
                                                          count = 0;
                                                        	for(int i = 1; i <= N; i++){
                                                            	for(int j = 1; j <= N; j++){
                                                                	if(joutai[i]==1){
                                                                    	if(tof[i][j] != 0 && tof[i][j] != joutai[j]){
                                                                           count++;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                           if(count == 0){
                                                             kouho = 0;
                                                             for(int i= 1; i <= N; i++){
                                                             	kouho += joutai[i]%2;
                                                             }
                                                           		ans.push(kouho);
                                                           }
                                                          
                                                          
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                            	}
                            }
                        }
                    }
                }
            }
        }
    }
  }

  cout << ans.top() << endl;
  
}

Measured memory_bytes: 512