/*
 #pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
*/
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#define NDEBUG
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>
#include <list>
#include <functional>
#include <numeric>

//find out the use of the below
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define PI acos(-1)

vector<int> v[17];
vector<int> b[17];
int cnt;
bool check(int x) {
    cnt = 0;
    int ind = 1;
    int st[17];
    MEMS(st);
    //st =
    //-1 unknown
    //0 dishonest
    //1 honest and all his testimonies considered
    //2 honest and not registered the testimonies yet
    while (x != 0){
        if (x&1) {
            if (st[ind] == 0)
                return false;
            else if (st[ind] == 1)
                continue;
            st[ind] = 1;
            cnt++;
            for (int p : v[ind])
                if (st[p] != 0) {
                    if (st[p] == -1)
                        st[p] = 2;
                }
                else
                    return false;
            for (int p : b[ind])
                if (st[p] <= 0)
                    st[p] = 0;
                else
                    return false;
        }
        x >>= 1;
        ind++;
    }
    int mi = 1;
    for (int i = 1; i < 17; ++i) {
        i = min(mi, i);
        mi = 17;
        if (st[i] == 2) {
            st[i] = 1;
            cnt++;
            for (int p : b[i]) {
                if (st[p] <= 0)
                    st[p] = 0;
                else
                    return false;
            }
            for (int p: v[i]) {
                if (st[p] != 0) {
                    if (st[p] == -1) {
                        mi = min(mi, p);
                        st[p] = 2;
                    }
                } else
                    return false;
            }
        }
    }
    return true;
}
int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    fio;
    int n;
    cin >> n;
    for (int i = 1; i < n+1; ++i) {
        int a;
        cin >> a;
        for (int j = 0; j < a; ++j) {
            int x, y;
            cin >> x >> y;
            if (y)
                v[i].pb(x);
            else 
                b[i].pb(x);
        }
    }
    int ans = 0;
    int ord = (1<<n) -1;
    for (int i = ord; i >=0; i--) {
        if (check(i)){
            ans = max(ans, cnt);
        }
    }
    cout << ans;        

    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 256