#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

void printDP(vvi &dp){
    for(auto v: dp){
        for(auto x: v){
            cout << x << " ";
        }
        cout << endl;
    }
    cout << endl;
}

void inc(bitset<15> &a){
    a = a.to_ullong() +1;
}

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int,int>>> testimonies(n);
    vvi dp(n,vi(n,-1));
    for(int i = 0 ; i < n ; i ++ ){
        int q;
        cin >> q;
        vector<pair<int,int>> xy(q);
        for(int j = 0 ; j < q;j++){
            int f,s;
            cin >> f>> s;
            f--;

            xy[j] = {f,s};
            dp[f][i] = s;
        }
        testimonies[i]  = xy;
    }

//    printDP(dp);
    bitset<15> bp;
    int maxScore = 0;
    while (bp.count() < n){
        inc(bp);
        bool isValid = true;
        for(int i = 0 ; i <n;i++ ){
            isValid = true;
            if(bp[i]){
                for(int j = 0 ; j < n ; j++){
                    if(dp[i][j] == 0 && bp[j]){
                        isValid = false;
                        break;
                    }
                }
            }else{
                for(int j = 0 ; j < n ; j++){
                    if(dp[i][j] == 1 && bp[j]){
                        isValid = false;
                        break;
                    }
                }
            }
            if(!isValid){
                break;
            }
        }
        if(isValid){
            maxScore = max(maxScore,(int)bp.count());
        }
    }
    cout << maxScore;
    return 0;
}


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

int counter(int bits) {
    if (bits == 0) return 0;
    return counter(bits >> 1) + (bits & 1);
}

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<vector<int> > x(n+1, vector<int>(n+1));
    vector<vector<int> > y(n+1, vector<int>(n+1));
    for (size_t i = 1; i <= n; i++) {
        cin >> a[i];
        for (size_t j = 1; j <= a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
        }
    }

    int ans = 0;
    for (int bits = 1; bits < (1<<n); bits++) {
        bool can = true;
        for (int i = 1; i <= n; i++) {
            if (bits & 1<<(i-1)) {
                for (size_t j = 1; j <= a[i]; j++) {
                    if (((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) can = false;
                }
            }
        }
        if (can) ans = max(ans, counter(bits));
    }

    cout << ans << endl;
    return 0;
}
