N = int(eval(input()))

B = [[-1]*N for i in range(N)]



for i in range(N):

    tmpA = int(eval(input()))

    for j in range(tmpA):

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

        B[i][x-1] = y



zero1 = [0,1]

import itertools



ans = 0

for i in itertools.product(zero1,repeat=N):

    tmpans = sum(i)

    tmpshi = [-1]*N

    flag = 0

    for j in range(len(i)):

        if flag == 1:

            break

        if i[j]==1:

            for k in range(len(B[j])):

                if B[j][k] in [0,1]:

                    if B[j][k] == tmpshi[k] or tmpshi[k]==-1:

                        tmpshi[k]=B[j][k]

                    else:

                        flag = 1

                        break

    flag1 = 0

    if flag == 0:

        for j in range(N):

            if i[j]!=tmpshi[j] and tmpshi[j]!=-1:

                flag1 = 1

                break

        if flag1 == 0:

            ans = max(ans,tmpans)

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

B = [[-1]*N for i in range(N)]



for i in range(N):

    tmpA = int(eval(input()))

    for j in range(tmpA):

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

        B[i][x-1] = y



ans = 0



for i in range(1<<N):

    tmp = i

    tmpans = 0

    while tmp!=0:

        tmpans += tmp%2

        tmp //= 2

    tmpshi = [-1]*N

    flag = 0

    for j in range(N):

        if flag == 1:

            break

        if ((i>>j)&1)==1:

            for k in range(N):

                if B[j][k] != -1:

                    if B[j][k] == tmpshi[k] or tmpshi[k]==-1:

                        tmpshi[k]=B[j][k]

                    else:

                        flag = 1

                        break

    flag1 = 0

    if flag == 0:

        for j in range(N):

            if ((i>>j)&1)!=tmpshi[j] and tmpshi[j]!=-1:

                flag1 = 1

                break

        if flag1 == 0:

            ans = max(ans,tmpans)

print(ans)
N = int(eval(input()))
B = [[-1] * N for i in range(N)]
for i in range(N):
    tmpA = int(eval(input()))
    for j in range(tmpA):
        x, y = list(map(int, input().split()))
        B[i][x - 1] = y
zero1 = [0, 1]
import itertools

ans = 0
for i in itertools.product(zero1, repeat=N):
    tmpans = sum(i)
    tmpshi = [-1] * N
    flag = 0
    for j in range(len(i)):
        if flag == 1:
            break
        if i[j] == 1:
            for k in range(len(B[j])):
                if B[j][k] in [0, 1]:
                    if B[j][k] == tmpshi[k] or tmpshi[k] == -1:
                        tmpshi[k] = B[j][k]
                    else:
                        flag = 1
                        break
    flag1 = 0
    if flag == 0:
        for j in range(N):
            if i[j] != tmpshi[j] and tmpshi[j] != -1:
                flag1 = 1
                break
        if flag1 == 0:
            ans = max(ans, tmpans)
print(ans)

N = int(eval(input()))
B = [[-1] * N for i in range(N)]
for i in range(N):
    tmpA = int(eval(input()))
    for j in range(tmpA):
        x, y = list(map(int, input().split()))
        B[i][x - 1] = y
ans = 0
for i in range(1 << N):
    tmp = i
    tmpans = 0
    while tmp != 0:
        tmpans += tmp % 2
        tmp //= 2
    tmpshi = [-1] * N
    flag = 0
    for j in range(N):
        if flag == 1:
            break
        if ((i >> j) & 1) == 1:
            for k in range(N):
                if B[j][k] != -1:
                    if B[j][k] == tmpshi[k] or tmpshi[k] == -1:
                        tmpshi[k] = B[j][k]
                    else:
                        flag = 1
                        break
    flag1 = 0
    if flag == 0:
        for j in range(N):
            if ((i >> j) & 1) != tmpshi[j] and tmpshi[j] != -1:
                flag1 = 1
                break
        if flag1 == 0:
            ans = max(ans, tmpans)
print(ans)

-zero1 = [0, 1] -import itertools - -for i in itertools.product(zero1, repeat=N): -    tmpans = sum(i) +for i in range(1 << N): +    tmp = i +    tmpans = 0 +    while tmp != 0: +        tmpans += tmp % 2 +        tmp //= 2 -    for j in range(len(i)): +    for j in range(N): -        if i[j] == 1: -            for k in range(len(B[j])): -                if B[j][k] in [0, 1]: +        if ((i >> j) & 1) == 1: +            for k in range(N): +                if B[j][k] != -1: -            if i[j] != tmpshi[j] and tmpshi[j] != -1: +            if ((i >> j) & 1) != tmpshi[j] and tmpshi[j] != -1: