#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
using namespace std::chrono; 
 
//VARS
#define int               long long
#define ld                long double
#define mod1              1000000007
#define mod2              998244353
#define pi               3.14159265358979323846
//#define hs                100006
#define inf               1e18
#define ninf              -1*(1e18)
 
#define pb                push_back
#define mp                make_pair
#define all(x)            (x).begin(),(x).end()
#define fi                first
#define se                second
#define vc                vector
#define pii               pair<int,int>
#define msi               map<string,int>
#define mii               map<int,int>
#define psi               pair<string,int>
#define pis               pair<int,string>
#define endl              "\n"
 
//INPUT
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define repe(i,a,b)       for(int i=a;i<=b;i++)
#define bac(i,a,b)        for(int i=a;i>b;i--)
#define bace(i,a,b)       for(int i=a;i>=b;i--)
 
//FAST
#define ios               ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
//FUNCTIONS
#define DECIMAL(n)        std::cout << std::fixed << std::setprecision(n)
#define SORT(v)           sort(all(v))
#define RSORT(v)          sort(all(v),greater<int>())
#define REVERSE(v)        reverse(ALL(v))
#define GCD(m,n)          __gcd(m,n)
#define LCM(m,n)          m*(n/GCD(m,n))
#define init(x,a)         memset(x,a,sizeof(x))
#define trav(a, x)        for(auto& a : x)
#define display(x)        trav(a,x) cout<<a<<" "; cout<<endl
#define pow(i,n)          (int)pow((int)i,n)
#define pow2(n)           ((int)1<<n)
 
void swp(int &a, int &b){
    auto temp=a;
    a=b;
    b=temp;
}

string decToBinary(int n,int sz)
    {
        string binaryNum;
        int i = 0;
        while (n > 0) {
            binaryNum+=to_string(n % 2);
                n = n / 2;
                i++;
            }
        reverse(all(binaryNum));
        binaryNum.insert(0,sz-binaryNum.size(),'0');
        return binaryNum;
                                   
    } 

void solve(){
    int n;
    cin>>n;
    vc<vc<pii>> v(n);
    int a,x,y;
    rep(i,0,n){
        cin>>a;
        rep(j,0,a){
            cin>>x>>y;
            v[i].pb(mp(x,y));
        }
    }
    int last = pow2(n);
    int ans=-1;
    rep(i,0,last){
        string lol = decToBinary(i,n);
        int meh=count(all(lol),'1');
        rep(j,0,n){
            if(lol[j]=='1'){
                rep(k,0,v[j].size()){
                    int huh1 = v[j][k].se,huh2=v[j][k].fi;
                    if(huh1==0 && lol[huh2-1]!='0'){
                        meh=0;
                        break;
                    }
                    else if(huh1==1 && lol[huh2-1]=='0'){
                        meh=0;
                        break;
                    }
                }
            }
        }
        ans=max(ans,meh);
    }
    cout<<ans;
}
 
signed main(){
    ios   

    int q=1;
    //cin>>q;
    while(q--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 256