using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.ReadInt;
            int[] a = new int[n];
            var xy = new Dictionary<int, List<int[]>>();
            for (int i = 0; i < n; i++)
            {
                a[i] = IO.ReadInt;
                var tmp = new List<int[]>();
                xy[i] = tmp;
                for (int j = 0; j < a[i]; j++)
                {
                    xy[i].Add(IO.ReadSplitInt.ToArray());
                }
            }

            int ans = 0;
            for (int i = 0; i < (1 << n); i++)
            {
                var status = new int[n];
                for (int j = 0; j < n; j++)
                {
                    var tmp = (i >> j) & 1;
                    // 1 or 0 の配列
                    status[j] = tmp;
                }

                bool f = true;
                for (int j = 0; j < n; j++)
                {
                    // 不親切な人の発言は無視
                    if (status[j] == 0) continue;

                    var tmp = xy[j];
                    for (int k = 0; k < a[j]; k++)
                    {
                        int x = tmp[k][0];
                        int y = tmp[k][1];
                        if (status[x - 1] != y)
                        {
                            f = false;
                            break;
                        }
                    }
                }
                // 正直な人の発言すべてに矛盾がないとき
                if (f)
                {
                    ans = Max(ans, status.Where(x => x == 1).Count());
                }
            }
            WriteLine(ans);
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

Measured memory_bytes: 17496