from itertools import product

N = int(eval(input()))

G = {i:[] for i in range(1,N+1)}

for i in range(1,N+1):

    K = int(eval(input()))

    for j in range(K):

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

cmax = 0

for z in product((0,1),repeat=N):

    flag = 0

    for i in range(N):

        if z[i]==1:

            ind = i+1

            for [x,y] in G[ind]:

                if z[x-1]==y:continue

                else:

                    flag=1

                    break

            if flag==1:

                break

    if flag==0:

        cmax = max(cmax,sum(z))

print(cmax)
from itertools import product

N = int(eval(input()))

G = {i:[] for i in range(1,N+1)}

for i in range(1,N+1):

    a = int(eval(input()))

    G[i] = [list(map(int,input().split())) for _ in range(a)]

cmax = 0

for z in product((0,1),repeat=N+1):

    if z[0]==0:

        X = []

        for i in range(1,N+1):

            if z[i]==1:

                X.append(i)

        A = []

        B = []

        for i in X:

            for x,y in G[i]:

                if y==1:

                    A.append(x)

                else:

                    B.append(x)

        flag = 0

        for a in A:

            if a not in X:

                flag = 1

                break

        for b in B:

            if b in X:

                flag = 1

                break

        if flag==0:

            cmax = max(cmax,sum(z[1:]))

print(cmax)
from itertools import product

N = int(eval(input()))
G = {i: [] for i in range(1, N + 1)}
for i in range(1, N + 1):
    K = int(eval(input()))
    for j in range(K):
        G[i].append(list(map(int, input().split())))
cmax = 0
for z in product((0, 1), repeat=N):
    flag = 0
    for i in range(N):
        if z[i] == 1:
            ind = i + 1
            for [x, y] in G[ind]:
                if z[x - 1] == y:
                    continue
                else:
                    flag = 1
                    break
            if flag == 1:
                break
    if flag == 0:
        cmax = max(cmax, sum(z))
print(cmax)

from itertools import product

N = int(eval(input()))
G = {i: [] for i in range(1, N + 1)}
for i in range(1, N + 1):
    a = int(eval(input()))
    G[i] = [list(map(int, input().split())) for _ in range(a)]
cmax = 0
for z in product((0, 1), repeat=N + 1):
    if z[0] == 0:
        X = []
        for i in range(1, N + 1):
            if z[i] == 1:
                X.append(i)
        A = []
        B = []
        for i in X:
            for x, y in G[i]:
                if y == 1:
                    A.append(x)
                else:
                    B.append(x)
        flag = 0
        for a in A:
            if a not in X:
                flag = 1
                break
        for b in B:
            if b in X:
                flag = 1
                break
        if flag == 0:
            cmax = max(cmax, sum(z[1:]))
print(cmax)

-    K = int(eval(input())) -    for j in range(K): -        G[i].append(list(map(int, input().split()))) +    a = int(eval(input())) +    G[i] = [list(map(int, input().split())) for _ in range(a)] -for z in product((0, 1), repeat=N): -    flag = 0 -    for i in range(N): -        if z[i] == 1: -            ind = i + 1 -            for [x, y] in G[ind]: -                if z[x - 1] == y: -                    continue +for z in product((0, 1), repeat=N + 1): +    if z[0] == 0: +        X = [] +        for i in range(1, N + 1): +            if z[i] == 1: +                X.append(i) +        A = [] +        B = [] +        for i in X: +            for x, y in G[i]: +                if y == 1: +                    A.append(x) -                    flag = 1 -                    break -            if flag == 1: +                    B.append(x) +        flag = 0 +        for a in A: +            if a not in X: +                flag = 1 -    if flag == 0: -        cmax = max(cmax, sum(z)) +        for b in B: +            if b in X: +                flag = 1 +                break +        if flag == 0: +            cmax = max(cmax, sum(z[1:]))