using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var _MemberCount = GetInput_int()[0];
            List<Dictionary<int, int>> _syougen = new List<Dictionary<int, int>>();
            for (int i = 0; i < _MemberCount; i++)
            {
                _syougen.Add(new Dictionary<int, int>());
                var checkCoadCount = GetInput_int()[0];
                for(int j = 0; j < checkCoadCount; j++)
                {
                    var input = GetInput_int();
                    _syougen[i].Add(input[0],input[1]);
                }
            }

            Stack<int> _checkStack = new Stack<int>();
            for(int i = 0; i < _MemberCount; i++)
            {
                _checkStack.Push(1);
            }
            int max = 0;

            for(int bit = 0; bit < (1 << _MemberCount); bit++)
            {
                string data = Convert.ToString(bit, 2).PadLeft(_MemberCount, '0');
                
                bool allsuccess = true;
                bool success = true;
                for(int j = 0; j < _MemberCount; j++)
                {
                    if (data[j] == '0') continue;
                    foreach(var d in _syougen[j])
                    {
                        bool check = data[d.Key-1].ToString() == d.Value.ToString();
                        if (!check)
                        {
                            success = false;
                            break;
                        }
                    }
                    if (!success)
                    {
                        allsuccess = false;
                        break;
                    }
                }
                if (allsuccess)
                {
                    var sum = data.Length - data.Replace("1", "").Length;
                    if (max < sum) max = sum;
                }
            }
            Console.WriteLine(max);
        }
        #region input
        

        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion

        static long mod = 1000000000 + 7;
    }
}

Measured memory_bytes: 15564