import itertools

n=int(eval(input()))

la=[]

for _ in range(n):

  d=int(eval(input()))

  for dd in range(d):

    x,y=list(map(int,input().split()))

    la.append([_,x-1,y])

ans=0

for i in itertools.product([0,1],repeat=n):

  s=sum(list(i))

  for l in la:

    if i[l[0]]==1 and i[l[1]]!=l[2]:

      break

  else:

    ans=max(ans,s)

print(ans)
import itertools

n=int(eval(input()))

l=[]

for i in range(n):

  d=int(eval(input()))

  for dd in range(d):

    x,y=list(map(int,input().split()))

    l.append([i,x-1,y])



ans=0

for p in itertools.product([0,1],repeat=n):

  for ll in l:

    if p[ll[0]]==1 and p[ll[1]]!=ll[2]:

      break

  else:

    ans=max(ans,sum(p))

print(ans)
import itertools

n = int(eval(input()))
la = []
for _ in range(n):
    d = int(eval(input()))
    for dd in range(d):
        x, y = list(map(int, input().split()))
        la.append([_, x - 1, y])
ans = 0
for i in itertools.product([0, 1], repeat=n):
    s = sum(list(i))
    for l in la:
        if i[l[0]] == 1 and i[l[1]] != l[2]:
            break
    else:
        ans = max(ans, s)
print(ans)

import itertools

n = int(eval(input()))
l = []
for i in range(n):
    d = int(eval(input()))
    for dd in range(d):
        x, y = list(map(int, input().split()))
        l.append([i, x - 1, y])
ans = 0
for p in itertools.product([0, 1], repeat=n):
    for ll in l:
        if p[ll[0]] == 1 and p[ll[1]] != ll[2]:
            break
    else:
        ans = max(ans, sum(p))
print(ans)

-la = [] -for _ in range(n): +l = [] +for i in range(n): -        la.append([_, x - 1, y]) +        l.append([i, x - 1, y]) -for i in itertools.product([0, 1], repeat=n): -    s = sum(list(i)) -    for l in la: -        if i[l[0]] == 1 and i[l[1]] != l[2]: +for p in itertools.product([0, 1], repeat=n): +    for ll in l: +        if p[ll[0]] == 1 and p[ll[1]] != ll[2]: -        ans = max(ans, s) +        ans = max(ans, sum(p))