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;
            while (true)
            {
                var tempList = _checkStack.ToArray();
                tempList.Reverse();
                //Console.Write("set:");
                //foreach(var data in tempList)
                //{
                //    Console.Write(data+",");
                //}
                //Console.Write("\n");
                bool allSuccess = true;
                for(int i = 0; i < _MemberCount; i++)
                {
                    if (tempList[i] == 0) continue;
                    bool success = true;
                    foreach(var data in _syougen[i])
                    {
                        bool check= tempList[data.Key-1] == data.Value;
                        if (!check)
                        {
                            success = false;
                            break;
                        }
                    }
                    if (!success)
                    {
                        allSuccess = false;
                        break;
                    }
                }

                if (allSuccess)
                {
                    //Console.WriteLine("success");
                    int tempResult = 0;
                    foreach(var data in tempList)
                    {
                        if (data == 1) tempResult++;
                    }
                    if (max < tempResult) max = tempResult;
                }

                //全探索
                int head = 0;
                while (head == 0)
                {
                    if (_checkStack.Count == 0) break;
                    head = _checkStack.Pop();
                }
                if (_checkStack.Count == 0&&head==0) break;
                _checkStack.Push(0);
                while (_checkStack.Count < _MemberCount)
                {
                    _checkStack.Push(1);
                }
            }

            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: 17616