using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        var matrix = new int[n, n];

        for (int i = 0; i < n; i++)
        {
            int a = sc.nextInt();
            for (int j = 0; j < a; j++)
            {
                int x = sc.nextInt();
                int y = sc.nextInt();
                if (y == 0) matrix[i, x - 1] = 2;
                else matrix[i, x - 1] = 1;
            }
        }

        //for (int i = 0; i < n; i++)
        //{
        //    for (int j = 0; j < n; j++)
        //    {
        //        Debug.Write("\t" + matrix[i, j]);
        //    }
        //    Debug.Write("\n");
        //}

        int ans = 0;

        for (int i = 0; i < 1 << n; i++)
        {
            int tmp = 0;
            var a = new bool[n];
            for (int j = 0; j < n; j++)
            {
                if ((1 & i >> j) == 1)
                {
                    a[j] = true;
                    tmp++;
                }
            }
            for (int j = 0; j < n; j++)
            {
                if (a[j])
                {
                    for (int t = 0; t < n; t++)
                    {
                        if (matrix[j, t] == 1 && !a[t])
                        {
                            tmp = 0;
                            break;
                        }
                        else if (matrix[j, t] == 2 && a[t])
                        {
                            tmp = 0;
                            break;
                        }
                    }
                }
                if (tmp == 0) break;
            }
            ans = Math.Max(ans, tmp);
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13268