from itertools import product as pro



n = int(eval(input()))

xy = []

for i in range(n):

    a_i = int(eval(input()))

    xy.append([tuple(map(int, input().split())) for _ in range(a_i)])



ans = 0

for l in pro([0, 1], repeat=n):

    for i, t in enumerate(l):

        if t == 1:

            if not all(l[x-1] == y for x, y in xy[i]):

                break

    else:

        ans = max(ans, sum(l))



print(ans)
from itertools import product



n = int(eval(input()))

xy = []

for _ in range(n):

    a = int(eval(input()))

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

    xy.append(tmp)



ans = 0

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

    for i, liar in enumerate(bit):

        if liar and any(bit[x - 1] != y for x, y in xy[i]):

            break

    else:

        ans = max(ans, sum(bit))

print(ans)

from itertools import product as pro

n = int(eval(input()))
xy = []
for i in range(n):
    a_i = int(eval(input()))
    xy.append([tuple(map(int, input().split())) for _ in range(a_i)])
ans = 0
for l in pro([0, 1], repeat=n):
    for i, t in enumerate(l):
        if t == 1:
            if not all(l[x - 1] == y for x, y in xy[i]):
                break
    else:
        ans = max(ans, sum(l))
print(ans)

from itertools import product

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

-from itertools import product as pro +from itertools import product -for i in range(n): -    a_i = int(eval(input())) -    xy.append([tuple(map(int, input().split())) for _ in range(a_i)]) +for _ in range(n): +    a = int(eval(input())) +    tmp = [list(map(int, input().split())) for _ in range(a)] +    xy.append(tmp) -for l in pro([0, 1], repeat=n): -    for i, t in enumerate(l): -        if t == 1: -            if not all(l[x - 1] == y for x, y in xy[i]): -                break +for bit in product([0, 1], repeat=n): +    for i, liar in enumerate(bit): +        if liar and any(bit[x - 1] != y for x, y in xy[i]): +            break -        ans = max(ans, sum(l)) +        ans = max(ans, sum(bit))