import itertools

n = int(eval(input()))

data = []

for x in range(n):

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

        k, l = list(map(int, input().split()))

        data.append((x, k - 1, l))

ans = 0

for i in itertools.product([1,0], repeat=n):

    s = sum(i)

    for g in data:

        if i[g[0]] == 1 and i[g[1]] != g[2]:

            s = 0

            break

    ans = max(ans, s)

print(ans)
import itertools

n = int(eval(input()))

data = []

for x in range(n):

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

        k, l = list(map(int, input().split()))

        data.append((x, k - 1, l))

ans = 0

for i in itertools.product([1,0], repeat=n):

    s = True

    for g in data:

        if i[g[0]] == 1 and i[g[1]] != g[2]:

            s = False

            break

    if s:

        ans = max(ans, sum(i))

print(ans)
import itertools

n = int(eval(input()))
data = []
for x in range(n):
    for y in range(int(eval(input()))):
        k, l = list(map(int, input().split()))
        data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
    s = sum(i)
    for g in data:
        if i[g[0]] == 1 and i[g[1]] != g[2]:
            s = 0
            break
    ans = max(ans, s)
print(ans)

import itertools

n = int(eval(input()))
data = []
for x in range(n):
    for y in range(int(eval(input()))):
        k, l = list(map(int, input().split()))
        data.append((x, k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
    s = True
    for g in data:
        if i[g[0]] == 1 and i[g[1]] != g[2]:
            s = False
            break
    if s:
        ans = max(ans, sum(i))
print(ans)

-    s = sum(i) +    s = True -            s = 0 +            s = False -    ans = max(ans, s) +    if s: +        ans = max(ans, sum(i))