N = int(eval(input()))



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

for i in range(N):

    a = int(eval(input()))

    for j in range(a):

        b, c = list(map(int, input().split()))

        X[i][b-1] = c

ans = 0

for i in range(2**N):

    Y = [0]*(N)

    for j in range(N):

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

            Y[j] = 1

    flag = True

    for j in range(N):

        if Y[j] == 1:

            for k in range(N):

                if X[j][k] == -1:

                    continue

                if X[j][k] != Y[k]:

                    flag = False

    if flag:

        ans = max(ans, sum(Y))



print(ans)
import itertools



N = int(eval(input()))



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

for i in range(N):

    a = int(eval(input()))

    for j in range(a):

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

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



saidai = 0

for i in itertools.product(list(range(2)), repeat=N):

    ans = list(i)

    Flag = True

    for j in range(N):

        if ans[j] == 1:

            for k in A[j]:

                if ans[k[0]] == k[1] or ans[k[0]] == -1:

                    ans[k[0]] = k[1]

                else:

                    Flag = False

                    break

    if Flag == True:

        saidai = max(ans.count(1), saidai)



print(saidai)
N = int(eval(input()))
X = [[-1] * N for i in range(N)]
for i in range(N):
    a = int(eval(input()))
    for j in range(a):
        b, c = list(map(int, input().split()))
        X[i][b - 1] = c
ans = 0
for i in range(2**N):
    Y = [0] * (N)
    for j in range(N):
        if (i >> j) & 1:
            Y[j] = 1
    flag = True
    for j in range(N):
        if Y[j] == 1:
            for k in range(N):
                if X[j][k] == -1:
                    continue
                if X[j][k] != Y[k]:
                    flag = False
    if flag:
        ans = max(ans, sum(Y))
print(ans)

import itertools

N = int(eval(input()))
A = [[] for _ in range(N)]
for i in range(N):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        A[i].append([x - 1, y])
saidai = 0
for i in itertools.product(list(range(2)), repeat=N):
    ans = list(i)
    Flag = True
    for j in range(N):
        if ans[j] == 1:
            for k in A[j]:
                if ans[k[0]] == k[1] or ans[k[0]] == -1:
                    ans[k[0]] = k[1]
                else:
                    Flag = False
                    break
    if Flag == True:
        saidai = max(ans.count(1), saidai)
print(saidai)

+import itertools + -X = [[-1] * N for i in range(N)] +A = [[] for _ in range(N)] -        b, c = list(map(int, input().split())) -        X[i][b - 1] = c -ans = 0 -for i in range(2**N): -    Y = [0] * (N) +        x, y = list(map(int, input().split())) +        A[i].append([x - 1, y]) +saidai = 0 +for i in itertools.product(list(range(2)), repeat=N): +    ans = list(i) +    Flag = True -        if (i >> j) & 1: -            Y[j] = 1 -    flag = True -    for j in range(N): -        if Y[j] == 1: -            for k in range(N): -                if X[j][k] == -1: -                    continue -                if X[j][k] != Y[k]: -                    flag = False -    if flag: -        ans = max(ans, sum(Y)) -print(ans) +        if ans[j] == 1: +            for k in A[j]: +                if ans[k[0]] == k[1] or ans[k[0]] == -1: +                    ans[k[0]] = k[1] +                else: +                    Flag = False +                    break +    if Flag == True: +        saidai = max(ans.count(1), saidai) +print(saidai)