using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;


class Program
{


    static void Main()
    {
        int N = ReadInt();
        Tuple<int, int>[][] testimonies = new Tuple<int, int>[N][];
        for (int i = 0; i < N; i++)
        {
            int A = ReadInt();
            testimonies[i] = new Tuple<int, int>[A];
            testimonies[i] = ReadTupleInt(A);
        }

        int ans = BitSearch(N, people => {

            int count = 0;
            for (int i = 0; i < people.Length; i++)
            {
                if(people[i] == 1)
                {
                    count++;
                    for (int j = 0; j < testimonies[i].Length; j++)
                    {
                        int obj = testimonies[i][j].Item1-1;
                        if (people[obj] == testimonies[i][j].Item2)
                        {
                            people[obj] = testimonies[i][j].Item2;
                        }
                        else return -1;
                    }
                }
            }
            return count;
        });
        
        WriteLine(ans);
        ReadLine();
    }


    public static int BitSearch(int digit,Func<int[],int> judge)
    {
        int max = 0;
        for (int i = 0; i < 2 << digit; i++)
        {
            int[] people = new int[digit];

            for (int j = 0; j < digit; j++)
            {
                people[j] = i >> j & 1;
            }
            int J = judge(people);
            max = Max(max,J);
        }
        return max;
    }


    #region Reader
    static string ReadStr()
    {
        return Console.ReadLine();
    }
    static string[] ReadStrN()
    {
        return Console.ReadLine().Split(' ');
    }
    static int ReadInt()
    {
        return Convert.ToInt32(Console.ReadLine());
    }
    static int[] ReadIntN()
    {
        return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    }
    static long ReadLong()
    {
        return Convert.ToInt64(Console.ReadLine());
    }
    static long[] ReadLongN()
    {
        return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    }
    static long[,] ReadLongMatrix(int r, int c)
    {
        var mat = new long[r, c];
        for (int i = 0; i < r; ++i)
        {
            var x = ReadLongN();
            for (int j = 0; j < c; ++j)
            {
                mat[i, j] = x[j];
            }
        }
        return mat;
    }
    static Tuple<string, string>[] ReadTupleStr(int n)
    {
        List<Tuple<string, string>> list = new List<Tuple<string, string>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadStrN();
            list.Add(new Tuple<string, string>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<long, long>[] ReadTupleLong(int n)
    {
        List<Tuple<long, long>> list = new List<Tuple<long, long>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadLongN();
            list.Add(new Tuple<long, long>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<int, int>[] ReadTupleInt(int n)
    {
        List<Tuple<int, int>> list = new List<Tuple<int, int>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadIntN();
            list.Add(new Tuple<int, int>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Tuple<double, double>[] ReadTupleDouble(int n)
    {
        List<Tuple<double, double>> list = new List<Tuple<double, double>>();
        for (int i = 0; i < n; ++i)
        {
            var ab = ReadLongN();
            list.Add(new Tuple<double, double>(ab[0], ab[1]));
        }
        return list.ToArray();
    }
    static Dictionary<int, HashSet<int>> ReadAdjacencyList(int N, int M)
    {
        Dictionary<int, HashSet<int>> dict = new Dictionary<int, HashSet<int>>();
        for (int i = 0; i <= N; ++i)
        {
            dict.Add(i, new HashSet<int>());
        }
        for (int i = 0; i < M; ++i)
        {
            var ab = ReadIntN();
            dict[ab[0]].Add(ab[1]);
            dict[ab[1]].Add(ab[0]);
        }
        return dict;
    }
    #endregion
}

Measured memory_bytes: 15568