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





def solve(bit):

    for i, j in enumerate(bit):

        if j == 1:

            for x, y in xy[i]:

                if bit[x - 1] != y:

                    return 0

    return sum(bit)





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):

    ans = max(ans, solve(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


def solve(bit):
    for i, j in enumerate(bit):
        if j == 1:
            for x, y in xy[i]:
                if bit[x - 1] != y:
                    return 0
    return sum(bit)


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):
    ans = max(ans, solve(bit))
print(ans)

+ + +def solve(bit): +    for i, j in enumerate(bit): +        if j == 1: +            for x, y in xy[i]: +                if bit[x - 1] != y: +                    return 0 +    return sum(bit) + -    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)) +    ans = max(ans, solve(bit))