//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second
#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define findnot find_first_not_of
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}

lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
int main()
{
    kira;
    lli n;
    cin >> n;
    vector<pll> v[n];
    lli s, x, y;
    forz(i, n)
    {
        cin >> s;
        forz(j, s)
        {
            cin >> x >> y;
            v[i].pb({x - 1, y});
        }
    }
    lli c = 0;
    lli maxi = 0;
    for (int b = 0; b < (1 << n); b++)
    {
        vector<int> vis(n, -1);
        vector<int>sub;
        int f = 1;
        c = 0;
        for (int i = 0; i < n; i++)
        {
            if (b & (1 << i))
            {
                sub.pb(1);
                if (vis[i] == 0)
                {
                    f = 0;
                    break;
                }
                else
                    vis[i] = 1;
                for (auto x : v[i])
                {
                    if (x.S == 1)
                    {
                        if (vis[x.F] == 0)
                        {
                            f = 0;
                            break;
                        }
                        vis[x.F] = 1;
                    }
                    else
                    {
                        if (vis[x.F] == 1)
                        {
                            f = 0;
                            break;
                        }
                        vis[x.F] = 0;
                    }
                }
                if (f == 1)
                    c++;
                else
                    c = 0;
            }
            else
            {
                sub.pb(0);
                if (vis[i] == 1)
                {
                    f = 0;
                    break;
                }
            }
            if (f == 0)
                c = 0;
        }
        if (f == 1)
        {
            forz(i,n)if(vis[i]==-1)vis[i]=0;
            forz(i, n)
            {
                //p2(vis[i],sub[i]);
                if(vis[i]!=sub[i])
                {
                    f=0;
                    break;
                }
            }
        }
        if (f == 1)
            maxi = max(maxi, c);
    }
    cout << maxi;
    return 0;
}

Measured memory_bytes: 256