#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;


/*
                     Keep trying ..!!!!
                     The journey is more important
*/

#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define umapii unordered_map < int , int >
#define umapll unordered_map<ll,ll>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define ll long long
#define pi pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vs vector<string>
#define vi vector<int>
#define vll vector<ll>
#define vpi vector<pi>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define FOR(i,a,b) for(int i = a;i <= b; i++)

// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

const ll mod = 1000000007;
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % mod;
        ex >>= 1ll;
        x = (x * x) % mod;
    }
    return ans;
}
void pr(ll x){
    vi dig;
    while(x > 0){
        dig.pb(x % 2);
        x /= 2;
    }
    for(int i = dig.size()-1; i>=0;i--){
             cout << dig[i];
    }
    cout<<'\n';
}

const int inf = 1e9 + 7;
const int N = 16;
ll v[20], vec[20];
int main(){
    ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int num;
        cin >> num;
        v[i] = 0; vec[i]=0;
        for(int j = 0; j < num; j++){
                 int x , y;
                 cin >> x >> y;
                 if(y == 1) v[i] = (v[i] | (1 << (x - 1)));
                 else vec[i] = (vec[i] | (1 << (x-1)));
        }
    }
    // cerr<<"binary\n";
    // for(int i=1;i<=n;i++){
    //    cerr<<i<<"-->"; pr(v[i]);
    // }
    // cout<<'\n';
    int ans = 0;
    for(ll mask = 0; mask < (1 << n); ++mask){
        // assuming mask people are honest
        ll tt=0,li=0;
        for(int i = 1; i <= n; i++){
            if((mask & (1<<(i - 1)))){
                tt = (tt | v[i]);
                li = (li | vec[i]);
            }
        }
        // cerr<<"for mask = "; pr(mask);
        // cerr<<"q = "; pr(q);
        if((mask & tt) == tt && (li & mask) == 0){
                ans = max(ans , __builtin_popcount(mask));
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 256