Imports System

Public Class Program

    Public Shared Sub Main(args As String())

        Dim N As Integer = Integer.Parse(Console.ReadLine)

        Dim Man(N - 1, N - 1) As Integer



        For i As Integer = 0 To N - 1
            Dim Ai As Integer = Integer.Parse(Console.ReadLine)

            For j As Integer = 0 To Ai - 1

                Dim Input() As String = Console.ReadLine.Split(" ")
                Man(i, Integer.Parse(Input(0) - 1)) = Integer.Parse(Input(1)) + 1
            Next

        Next

        Dim status(N - 1) As Boolean
        Dim maxcnt As Integer = 0


        For s As UInt16 = 0 To 2 ^ N - 1
            Try
                Dim cnt As Integer = 0

                For d As Integer = 0 To N - 1
                    status(d) = (s >> d) And 1

                    If status(d) Then
                        cnt += 1
                    End If

                Next

                If maxcnt > cnt Then
                    Throw New ieieie
                End If

                For d As Integer = 0 To N - 1
                    If status(d) Then

                        For dd As Integer = 0 To N - 1

                            If (Man(d, dd) = 2) AndAlso (status(dd) = False) Then
                                Throw New ieieie
                            End If

                            If (Man(d, dd) = 1) AndAlso (status(dd) = True) Then
                                Throw New ieieie
                            End If

                        Next

                    End If
                Next

                maxcnt = cnt
            Catch ex As ieieie

            End Try



        Next


        Console.WriteLine(maxcnt)




    End Sub
End Class

Public Class ieieie : Inherits Exception

End Class