n = int(input())
li = []
for i in range(n):
  a = int(input())
  li_2 = [list(map(int, input().split())) for _ in range(a)]
  li.append(li_2)
def judge(bit): 
  b =1
  """正直者と嘘つきの決め方を一つ固定"""
  for i in range(n):
    if bit & (1<<i) == False:
      continue
    else:
      for xy in li[i]:
        x = xy[0]
        y = xy[1]
        if y == 1 and bit & (1<<x)==False:
          b = 0
        if y == 0 and bit & (1<<x):
          b = 0
      if b == 1:
        return True
      else:
        return False
res = 0
for bit in range(n):
  if judge(bit):
    count = 0
    for i in range(n):
      if bit & (1<<i):
        count += 1
    res = max(res,count)
print(res)