from itertools import product



N = int(eval(input()))

A = []

XY = [[] for _ in range(N)]

for i in range(N):

  A.append(int(eval(input()))) 

  for j in range(A[i]):

    XY[i].append(list(map(int, input().split())))



ans = 0

for pattern in product(list(range(2)), repeat=N): # 0:不正直 1:正直

  flag = True

  for i in range(N):

    if pattern[i]: # iさんが正直と仮定

      # 発言と一致するか？

      for a in range(A[i]):

        if pattern[XY[i][a][0]-1] != XY[i][a][1]:

          flag = False

          break

  if flag:

    ans = max(ans, sum(pattern))



print(ans)
N = int(eval(input()))

XY = []

for i in range(N):

  A = int(eval(input()))

  XY.append([list(map(int, input().split())) for _ in range(A)])



ans = 0

for bit in range(1 << N):

  honest_cnt = 0

  flag = True

  for i in range(N):

    if (bit >> i) & 1 == 0:

      continue

    honest_cnt += 1

    for x, y in XY[i]:

      if (bit >> (x-1)) & 1 != y:

        flag = False

        break

  if flag:

    ans = max(ans, honest_cnt)

    

print(ans)
from itertools import product

N = int(eval(input()))
A = []
XY = [[] for _ in range(N)]
for i in range(N):
    A.append(int(eval(input())))
    for j in range(A[i]):
        XY[i].append(list(map(int, input().split())))
ans = 0
for pattern in product(list(range(2)), repeat=N):  # 0:不正直 1:正直
    flag = True
    for i in range(N):
        if pattern[i]:  # iさんが正直と仮定
            # 発言と一致するか？
            for a in range(A[i]):
                if pattern[XY[i][a][0] - 1] != XY[i][a][1]:
                    flag = False
                    break
    if flag:
        ans = max(ans, sum(pattern))
print(ans)

N = int(eval(input()))
XY = []
for i in range(N):
    A = int(eval(input()))
    XY.append([list(map(int, input().split())) for _ in range(A)])
ans = 0
for bit in range(1 << N):
    honest_cnt = 0
    flag = True
    for i in range(N):
        if (bit >> i) & 1 == 0:
            continue
        honest_cnt += 1
        for x, y in XY[i]:
            if (bit >> (x - 1)) & 1 != y:
                flag = False
                break
    if flag:
        ans = max(ans, honest_cnt)
print(ans)

-from itertools import product - -A = [] -XY = [[] for _ in range(N)] +XY = [] -    A.append(int(eval(input()))) -    for j in range(A[i]): -        XY[i].append(list(map(int, input().split()))) +    A = int(eval(input())) +    XY.append([list(map(int, input().split())) for _ in range(A)]) -for pattern in product(list(range(2)), repeat=N):  # 0:不正直 1:正直 +for bit in range(1 << N): +    honest_cnt = 0 -        if pattern[i]:  # iさんが正直と仮定 -            # 発言と一致するか？ -            for a in range(A[i]): -                if pattern[XY[i][a][0] - 1] != XY[i][a][1]: -                    flag = False -                    break +        if (bit >> i) & 1 == 0: +            continue +        honest_cnt += 1 +        for x, y in XY[i]: +            if (bit >> (x - 1)) & 1 != y: +                flag = False +                break -        ans = max(ans, sum(pattern)) +        ans = max(ans, honest_cnt)