N = int(eval(input()))

T = [[-1] * N for _ in range(N)]

for i in range(N):

    for _ in range(int(eval(input()))):

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

        T[i][x - 1] = y



ans = 0

for i in range(1 << N):

    is_kind = [i >> j & 1 for j in range(N)]

    found = True

    for j in range(N):

        if not is_kind[j]:

            continue

        for k in range(N):

            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]:

                continue

            found = False

    if found:

        ans = max(ans, sum(is_kind))

print(ans)

N = int(eval(input()))

T = [[-1] * N for _ in range(N)]

for i in range(N):

    for _ in range(int(eval(input()))):

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

        T[i][x - 1] = y



ans = 0

for i in range(1 << N):

    is_kind = [i >> j & 1 for j in range(N)]

    found = True

    for j in range(N):

        if not is_kind[j]:

            continue

        for k in range(N):

            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]:

                continue

            found = False

        if not found:

            break

    if found:

        ans = max(ans, sum(is_kind))

print(ans)

N = int(eval(input()))
T = [[-1] * N for _ in range(N)]
for i in range(N):
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        T[i][x - 1] = y
ans = 0
for i in range(1 << N):
    is_kind = [i >> j & 1 for j in range(N)]
    found = True
    for j in range(N):
        if not is_kind[j]:
            continue
        for k in range(N):
            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]:
                continue
            found = False
    if found:
        ans = max(ans, sum(is_kind))
print(ans)

N = int(eval(input()))
T = [[-1] * N for _ in range(N)]
for i in range(N):
    for _ in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        T[i][x - 1] = y
ans = 0
for i in range(1 << N):
    is_kind = [i >> j & 1 for j in range(N)]
    found = True
    for j in range(N):
        if not is_kind[j]:
            continue
        for k in range(N):
            if j == k or T[j][k] == -1 or T[j][k] == is_kind[k]:
                continue
            found = False
        if not found:
            break
    if found:
        ans = max(ans, sum(is_kind))
print(ans)

+        if not found: +            break