#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

lli n;

int main(void){
    cin >> n;
    vector<vector<pair<lli, lli>>> t(n);
    rep(i, n){
        lli ai;
        cin >> ai;
        rep(j, ai){
            lli x, y;
            cin >> x >> y;
            t[i].push_back({x-1, y});
        }
    }
    lli ans = 0;
    rep(b, (1<<n)){
        bool ok = true;
        rep(j, n){
            if(b>>j&1){
                rep(k, t[j].size()){
                    lli u = t[j][k].second;
                    lli v = b>>t[j][k].first&1;
                    if(u != v){
                        ok = false;
                    }
                }
            }
        }
        if(ok){
            ans = max(ans, (lli)__builtin_popcount(b));
        }
    }
    cout << ans << endl;
    return 0;
}

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VVI x(n), y(n);
    REP(i,n){
        int a = in();
        REP(j,a){
            x[i].push_back(in() - 1);
            y[i].push_back(in());
        }
    }
    int ans = 0;
    REP(mask,1<<n){
        bool f = true;
        int cnt = 0;
        REP(i,n) if ((mask >> i) & 1) cnt++;

        REP(i,n){
            if (((mask >> i) & 1) == 0) continue;
            REP(j,x[i].size()){
                if (((mask >> x[i][j]) & 1) != y[i][j]) f = false;
            }
        }
        if (f) chmax(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}
