using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        var waaaa = new waaaa();
        waaaa.Solve();
    }
}

public class waaaa
{
    const int MOD = 1000000007;
    const int INF = 1 << 20;
    const long INFL = 1 << 62;
    const int MOD2 = 998244353;

    myinout IO = new myinout();
    Math2 mmath = new Math2();



    public void Solve()
    {
        //ここから
        var N = IO.Int1;
        int[,] x = new int[N, N];
        int[,] y = new int[N, N];

        for (int i = 0; i < N; ++i)
        {
            for (int j = 0; j < N; ++j)
            {
                x[i, j] = -1;
                y[i, j] = -1;
            }
        }

        for (int i = 0; i < N; ++i)
        {
            int A = IO.Int1;
            for (int j = 0; j < A; ++j)
            {
                var o = IO.IntM;
                x[i, j] = o[0] - 1;
                y[i, j] = o[1];
            }
        }
        int ans = 0;
        for (int i = 0; i < (1 << N); ++i)
        {
            int count = 0;
            bool f = true;
            for (int j = 0; j < N; ++j)
            {
                if (((i >> j) & 1) == 1)
                {
                    count++;
                    

                    bool f2 = true;
                    for(int k=0;k<N;++k){ //jのk番目の証言
                    var sss=x[j,k];
                        if((((i>>sss)&1)!=1&&y[j,k]==1)){
                            f=false;
                        }
                    }
                    for (int k = 0; k < N; ++k) //k番目の証人
                    {
                        for (int l = 0; l < N; ++l) //l番目の証言
                        {
                            if (((i >> k) & 1) == 1 && x[k, l] == j && y[k, l] == 0) f2 = false;
                        }
                    }

                    if (!f2)
                    {
                        f = false;
                        break;
                    }


                }
            }
            //IO.wri(f);
            if (f) ans = Math.Max(ans, count);
        }
        IO.wri(ans);

    }

}

//b-aで降順

public class Math2
{
    public long[] Fact;  //Nまでの階乗
    public long[] invFact;  //階乗の逆元

    //Nまでの階乗をセットしておく
    public void FactoricalModSet(long N, long MOD = 1000000007)
    {
        Fact = new long[N + 1];
        invFact = new long[N + 1];

        Fact[0] = 1;
        for (long i = 1; i <= N; ++i)
        {
            Fact[i] = Fact[i - 1] * i % MOD;
        }
        invFact[N] = pow(Fact[N], MOD - 2);

        for (long i = N; i > 0; --i)
        {
            invFact[i - 1] = invFact[i] * i % MOD;
        }

    }

    //nCr 引数:n r (mod)
    public long nCr(long n, long r, long MOD = 1000000007)
    {
        return (Fact[n] * invFact[r] % MOD * invFact[n - r] % MOD);
    }

    //階乗(O(logN)) 引数:底x n乗　(MOD)
    public long pow(long x, long n, long MOD = 1000000007)
    {
        long res = 1;
        while (n > 0)
        {
            if ((n & 1) != 0) res = res * x % MOD;
            x = x * x % MOD;
            n >>= 1;
        }
        return res;
    }

    //最大公約数 引数:整数x,y
    public long GCD(long x, long y)
    {
        while (y != 0)
        {
            var r = x % y;
            x = y;
            y = r;
        }
        return x;
    }

    //最小公倍数 引数:整数x,y
    public long LCM(long x, long y)
    {
        return x * y / GCD(x, y);
    }

    //素因数分解 引数:整数N
    public Dictionary<long, int> PrimeFactorization(long N)
    {
        var ret = new Dictionary<long, int>();

        for (long i = 2; i * i <= N; ++i)
        {
            int cnt = 0;
            while (N % i == 0)
            {
                cnt++;
                N /= i;
            }
            if (cnt != 0) ret[i] = cnt;

        }
        if (N >= 2) ret[N] = 1;

        return ret;

    }

    //約数列挙
    public List<long> divisorenumrate(long N)
    {
        var ret = new List<long>();

        for (long i = 1; i * i <= N; ++i)
        {

            if (N % i == 0)
            {
                ret.Add(i);
                ret.Add(N / i);
            }

        }

        return ret;

    }

    public void Swap<T>(ref T a, ref T b)
    {
        var x = a;
        a = b;
        b = x;
    }

}

class myinout
{
    //in
    public string Str => Console.ReadLine();

    public string[] StrM => Str.Split(' ');

    public long[] LongM => StrM.Select(long.Parse).ToArray();
    public int[] IntM => StrM.Select(int.Parse).ToArray();
    public char[] CharM => Str.ToArray();
    public long Long1 => LongM[0];
    public int Int1 => IntM[0];

    //out
    public void wri<T>(T x)
    {
        Console.WriteLine(x);
    }

    public void yn(bool x)
    {
        if (x) wri("Yes");
        else wri("No");
    }

}


Measured memory_bytes: 13396