import itertools

n = int(eval(input()))

data = {}

for x in range(n):

    data[x] = []

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

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

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



ans = 0

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

    h = True

    for x in range(n):

        if i[x] == 1:

            for g in data[x]:

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

                    h = False

        if h == False:

            break

    if h == True:

        ans = max(ans, sum(list(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(list(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):
    data[x] = []
    for y in range(int(eval(input()))):
        k, l = list(map(int, input().split()))
        data[x].append((k - 1, l))
ans = 0
for i in itertools.product([1, 0], repeat=n):
    h = True
    for x in range(n):
        if i[x] == 1:
            for g in data[x]:
                if i[g[0]] != g[1]:
                    h = False
        if h == False:
            break
    if h == True:
        ans = max(ans, sum(list(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(list(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)

-data = {} +data = [] -    data[x] = [] -        data[x].append((k - 1, l)) +        data.append((x, k - 1, l)) -    h = True -    for x in range(n): -        if i[x] == 1: -            for g in data[x]: -                if i[g[0]] != g[1]: -                    h = False -        if h == False: +    s = sum(list(i)) +    for g in data: +        if i[g[0]] == 1 and i[g[1]] != g[2]: +            s = 0 -    if h == True: -        ans = max(ans, sum(list(i))) +    ans = max(ans, s)