Public Class Program
  Shared Sub Main()
    Dim n As Integer = Integer.Parse(Console.ReadLine())
    Dim a(0 To n - 1) As Integer
    Dim x(0 To n - 1)() As Integer
    Dim y(0 To n - 1)() As Integer
    For i As Integer = 0 To n - 1
      a(i) = Integer.Parse(Console.ReadLine())
      x(i) = New Integer(0 To a(i) - 1) {}
      y(i) = New Integer(0 To a(i) - 1) {}
      For j As Integer = 0 To a(i) - 1
        Dim xy As Integer() = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        x(i)(j) = xy(0)
        y(i)(j) = xy(1)
      Next
    Next
    
    Dim ans As Integer = 0
    For i As Integer = 0 To Math.Pow(2, n) - 1
      Dim katei(0 To n - 1) As Boolean
      For j As Integer = 0 To n - 1
        Dim z As Integer = (i >> j) And 1
        If z = 1 Then 
          katei(j) = True
        Else
          katei(j) = False
        End If
      Next
      
      Dim ok As Boolean = True
      For j As Integer = 0 To n - 1
        If katei(j) Then
          For k As Integer = 0 To a(j) - 1
            If Not katei(x(j)(k) - 1) = (y(j)(k) = 1) Then ok = False
          Next
        End If
      Next
      If ok Then
        ans = Math.Max(ans, Array.FindAll(Of Boolean)(katei, AddressOf IsTrue).Length())
      End If
    Next
    Console.WriteLine(ans.ToString())
  End Sub

  Private Shared Function IsTrue(element As Boolean) As Boolean
    Return element
  End Function
End Class