local mma = math.max
local mfl = math.floor
local n = io.read("*n")
local mul = 1
local say = {}
for i = 1, n do
  say[i] = {}
  local k = io.read("*n")
  for j = 1, k do
    local a, b = io.read("*n", "*n")
    say[i][a] = b
  end
  mul = mul * 2
end
local ret = 0
local state = {}
for im = 0, mul - 1 do
  local valid = true
  local tasks = {}
  for j = 1, n do
    if im % 2 == 1 then
      table.insert(tasks, j)
    end
    state[j] = im % 2
    im = mfl(im / 2)
  end
  local cnt = #tasks
  for j = 1, #tasks do
    local src = tasks[j]
    for k, v in pairs(say[src]) do
      if state[k] ~= v then
        valid = false
        break
      end
    end
    if not valid then break end
  end
  if valid then ret = mma(ret, cnt) end
end
print(ret)
