N = gets.to_i

says = []

N.times do
  a = gets.to_i

  words = []

  a.times do
    person, truth = gets.split.map(&:to_i)

    words << [person - 1, truth]
  end

  says << words
end

ans = 0

0.upto(2 ** N - 1) do |mask|
  success = true

  N.times do |n|
    next if mask[n] == 0

    words = says[n]

    words.each do |person, truth|
      if truth == 1
        if mask[person] == 0
          success = false
        end
      else
        if mask[person] == 1
          success = false
        end
      end
    end

    break unless success
  end

  if success
    ans = [ans, mask.to_s(2).count('1')].max
  end
end

puts ans
