from itertools import product



n = int(eval(input()))

xy = [[] for i in range(n)]



for i in range(n):

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

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



ans = 0

for bit in product([0, 1], repeat=n):

    f = 0

    for i, j in enumerate(bit):

        if j == 1:

            for x, y in xy[i]:

                if bit[x - 1] != y:

                    f = 1

    if f == 0:

        ans = max(ans, sum(bit))

print(ans)
from itertools import product



n = int(eval(input()))

xy = [[] for i in range(n)]



for i in range(n):

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

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



ans = 0

for bit in product([0, 1], repeat=n):

    f = 0

    for i, j in enumerate(bit):

        if j == 1:

            for x, y in xy[i]:

                if bit[x - 1] != y:

                    f = 1

                    break

    if f == 0:

        ans = max(ans, sum(bit))

print(ans)

from itertools import product

n = int(eval(input()))
xy = [[] for i in range(n)]
for i in range(n):
    for j in range(int(eval(input()))):
        xy[i].append(list(map(int, input().split())))
ans = 0
for bit in product([0, 1], repeat=n):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x - 1] != y:
                    f = 1
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

from itertools import product

n = int(eval(input()))
xy = [[] for i in range(n)]
for i in range(n):
    for j in range(int(eval(input()))):
        xy[i].append(list(map(int, input().split())))
ans = 0
for bit in product([0, 1], repeat=n):
    f = 0
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x - 1] != y:
                    f = 1
                    break
    if f == 0:
        ans = max(ans, sum(bit))
print(ans)

+                    break