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

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class JItem
    {
        public int X { get; set; }
        public int Y { get; set; }
    }

    class Solver
    {
        private List<List<JItem>> A = new List<List<JItem>>();
        private List<List<bool>> Patterns = new List<List<bool>>();

        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());

            var A = new List<List<JItem>>();
            for (int i = 0; i < N; i++)
            {
                var Ai = new List<JItem>();
                var jCount = int.Parse(Console.ReadLine());
                for (int j = 0; j < jCount; j++)
                {
                    var items = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                    Ai.Add(new JItem { X = items[0], Y = items[1] });
                }

                A.Add(Ai);
            }

            this.Patterns = PatternMaker.Make(new List<bool>(), N);
            var answer = 0;
            foreach (var pattern in Patterns)
            {
                var honestCount = 0;
                var match = true;
                for (int i = 0; i < pattern.Count; i++)
                {
                    if (pattern[i])
                    {
                        // 正直者である
                        honestCount++;
                        if (!this.IsHonest(A, i, pattern))
                        {
                            match = false;
                            break;
                        }
                    }
                    else
                    {
                        // 不親切な人
                    }
                }

                answer = match && honestCount > answer ? honestCount : answer;
            }

            Console.WriteLine(answer);
        }

        private bool IsHonest(List<List<JItem>> A, int i, List<bool> pattern)
        {
            foreach (var item in A[i])
            {
                if (item.Y == 1 != pattern[item.X - 1])
                {
                    return false;
                }
            }

            return true;
        }
    }

    public static class PatternMaker
    {
        public static List<List<bool>> Make(List<bool> list, int num)
        {
            var ret = new List<List<bool>>();

            var list1 = list.Select(x => x).ToList();
            list1.Add(true);
            var list2 = list.Select(x => x).ToList();
            list2.Add(false);

            if (num > 1)
            {
                ret.AddRange(Make(list1, num - 1));
                ret.AddRange(Make(list2, num - 1));
            }
            else
            {
                ret.Add(list1);
                ret.Add(list2);
            }

            return ret;
        }
    }
}


Measured memory_bytes: 26312