Imports System.Collections.Generic
Module ProblemC

    Sub Main()
        Dim n As Integer = Integer.Parse(Console.ReadLine)
        Dim prm() As Integer
        Dim a As Integer
        Dim s As New Dictionary(Of Integer, Dictionary(Of Integer, Integer))
        Dim v(n) As Integer
        Dim i, j, vs As Integer
        Dim c As Boolean
        Dim ans As Integer = 0

        For i = 1 To n
            a = Integer.Parse(Console.ReadLine)
            s(i) = New Dictionary(Of Integer, Integer)
            If a > 0 Then
                For j = 1 To a
                    prm = Array.ConvertAll(Of String, Integer)(Console.ReadLine.Split(" "c), AddressOf Integer.Parse)
                    s(i).Add(prm(0), prm(1))
                Next
            End If
        Next

        For i = 1 To Convert.ToInt32(2 ^ n) - 1

            vs = 0
            For j = 1 To n
                v(j) = If(((i >> j - 1) And 1) = 1, 1, 0)
                vs += v(j)
            Next

            c = True
            For j = 1 To n
                If v(j) = 1 AndAlso s(j).Count > 0 Then

                    For Each k As KeyValuePair(Of Integer, Integer) In s(j)
                        If v(k.Key) <> k.Value Then
                            c = False
                            Exit For
                        End If
                    Next

                End If
                If Not c Then Exit For
            Next

            If c Then
                ans = Math.Max(ans, vs)
            End If

        Next

        Console.WriteLine(ans.ToString)
    End Sub

End Module
