using System;
using System.Linq;
using System.Collections.Generic;

using SyrupBeans.Competitive.IO;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = InputParser.TakeInt32();
        var witness = new int[n + 1];
        var mention = new int[n + 1];
        for (int i = 1; i < witness.Length; ++i)
        {
            var a = InputParser.TakeInt32();
            for (int j = 0; j < a; ++j)
            {
                var xy = InputParser.TakeInt32Array(2);
                witness[i] |= xy[1] << xy[0] - 1;
                mention[i] |= 1 << xy[0] - 1;
            }
        }

        var max = 0;
        var upperBound = 1 << n;
        for (int i = 0; i < upperBound; ++i)
        {
            var k = 0;
            var ok = true;
            for (int j = 0; j < n && ok; ++j)
            {
                if ((i >> j & 1) == 0)
                {
                    continue;
                }
                var w = witness[j + 1];
                ok &= (w & mention[j + 1]) == (i & mention[j + 1]);
                ++k;
            }
            if (!ok)
            {
                continue;
            }
            max = Math.Max(max, k);
        }

        Console.WriteLine(max);
    }
}

namespace SyrupBeans.Competitive.IO
{
    public static class InputParser
    {
        public static string BufferdString { get; private set; }
        private static int index;
        private static char Peek => BufferdString[index];

        public static char TakeCharacter() => BufferdString[index++];

        static InputParser()
        {
            Reset();
        }

        public static void Reset()
        {
            InputParser.BufferdString = System.Console.In.ReadToEnd();
            InputParser.index = 0;
        }

        private static void SeekToken()
        {
            while (char.IsWhiteSpace(InputParser.Peek))
            {
                ++InputParser.index;
            }
        }

        private static char[] Separators { get; } = " \r\n".ToCharArray();

        private static int CountTokens(string terminator)
        {
            int k = 0;
            int i = InputParser.index;
            int t = InputParser.BufferdString.IndexOf(terminator, i);
            if (t < 0)
            {
                t = InputParser.BufferdString.Length;
            }
            var c = InputParser.Peek;
            while (i < 0 || t <= i)
            {
                while (char.IsWhiteSpace(c))
                {
                    ++i;
                    if (i >= t)
                    {
                        return k;
                    }
                    c = InputParser.BufferdString[i];
                }
                ++k;
                i = InputParser.BufferdString.IndexOfAny(Separators, i);
            }
            return k;
        }

        public static int TakeInt32()
        {
            InputParser.SeekToken();
            int sign = 1;
            if (InputParser.Peek == '-')
            {
                ++InputParser.index;
                sign = -1;
            }
            int x = 0;
            while (char.IsDigit(InputParser.Peek))
            {
                x = x * 10 + InputParser.TakeCharacter() - '0';
            }
            x *= sign;
            return x;
        }

        public static int[] TakeInt32Array(int length)
        {
            var xs = new int[length];
            for (int i = 0; i < xs.Length; ++i)
            {
                xs[i] = InputParser.TakeInt32();
            }
            return xs;
        }

        public static int[] TakeInt32Array(string terminator = "\0")
            => InputParser.TakeInt32Array(InputParser.CountTokens(terminator));
    }
}


Measured memory_bytes: 11092