#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define VOUT(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vout(v) VOUT(v,z);
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL);
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

void solve_old(ll N, std::vector<long long> A, vector<vector<ll>> x, vector<vector<ll>> y){
    // debg(N);
    // vout(A);
    // mout(x);
    // mout(y);
    ll n = N;
    ll maxn = 0;
    for (ll bit = 0; bit < (1<<n); bit++) {
        V f(N);
        V v;
        V w;
        for (ll i = 0; i < n; i++) {
            if(bit & (1<<i)) {
                v.push_back(i);
            }else{
                w.push_back(i);
            }
        }
    
        cout << bit << ": ";
        for (ll i = 0; i < v.size(); i++) {
            cout << v[i] << " ";
        }
        cout << endl;

        for (ll i = 0; i < v.size(); i++) {
            f[v[i]] = 1;
            ll num = A[v[i]]-1;
            for (ll j = 0; j < num; j++) {
                ll man = x[v[i]][j]-1;
                ll say = y[v[i]][j];
                f[man] = say;
            }
        }

        bool mujun = false;
        for (ll i = 0; i < w.size(); i++) {
            ll num = A[w[i]]-1;
            for (ll j = 0; j < num; j++) {
                ll man = x[w[i]][j]-1;
                ll say = y[w[i]][j];
                if(f[man] != !say) mujun = true;
            }
        }

        vout(f);
        debg(mujun);
        if(mujun){
            continue;
        }else{
            maxn = v.size();
        }

    }
    cout << maxn << "\n";
}

void solve(ll N, std::vector<long long> A, vector<vector<ll>> x, vector<vector<ll>> y){
    // debg(N);
    // vout(A);
    // mout(x);
    // mout(y);
    ll n = N;
    ll maxn = 0;
    for (ll bit = 0; bit < (1<<n); bit++) {
        V f(N);
        V v;
        V w;
        for (ll i = 0; i < n; i++) {
            if(bit & (1<<i)) {
                v.push_back(i);
            }else{
                w.push_back(i);
            }
        }
    
        // cout << bit << ": ";
        // for (ll i = 0; i < v.size(); i++) {
        //     cout << v[i] << " ";
        // }
        // cout << endl;

        for (ll i = 0; i < v.size(); i++) {
            f[v[i]] = 1;
        }

        bool mujun = false;
        for (ll i = 0; i < N; i++) {
            ll num = A[i];
            for (ll j = 0; j < num; j++) {
                ll man = x[i][j]-1;
                ll say = y[i][j];
                if(f[i]==1){
                    if(f[man] != say) mujun = true;
                }
                // else{
                //     if(f[man] == say) mujun = true;
                // }
            }
        }
        if(mujun){
            continue;
        }else{
            chmax(maxn, (ll)v.size());
            // maxn=max(maxn, (ll)v.size());
        }

    }
    cout << maxn << "\n";
}

int main(){
    ll N;
    cin >> N;
    std::vector<long long> A(N);
    vector<vector<ll>> x(N);
    vector<vector<ll>> y(N);
    for(int i = 0 ; i < N ; i++){
        cin >> A[i];
        if(A[i]>0){
            x[i].resize(A[i]);
            y[i].resize(A[i]);
            // x.resize(N, vector<ll>(A[i]));
            // y.resize(N, vector<ll>(A[i]));
            for (ll j = 0; j < A[i]; j++) {
                cin >> x[i][j] >> y[i][j];
            }
        }
    }
    solve(N, std::move(A), move(x), move(y));
    return 0;
}


Measured memory_bytes: 256