import sys

n = int(eval(input()))

a = [[-1 for _ in range(n)] for _ in range(n)]

for i in range(n):

    j = int(eval(input()))

    for s in range(j):

        x, y = list(map(int, input().split()))

        a[i][x-1] = y

r = 0

for i in range(2**n):

    s = bin(i)

    t = s[2:]

    t = t.rjust(n, '0')

    c = 1

    for j in range(n):

        if t[j] == '0':

            continue

        else:

            for p in range(n):            

                    if int(t[p]) == a[j][p] or a[j][p] == -1:

                        continue

                    else:

                        c = 0

                        break

    if c:

        r = max(r, sum(map(int, list(t))))

print(r)
n = int(eval(input()))

a = []

for i in range(n):

    a_ = int(eval(input()))

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



result = [0]

for i in range(1, 2**n):

    h = format(i, "0"+str(n)+"b")

    c = [int(j) for j in list(h)]

    checker = True

    for j in range(n):

        if c[j]:

            for x, y in a[j]:

                if c[x-1]!=y:

                    checker = False

                    break

    if checker:

        result.append(c.count(1))

print((max(result)))
import sys

n = int(eval(input()))
a = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
    j = int(eval(input()))
    for s in range(j):
        x, y = list(map(int, input().split()))
        a[i][x - 1] = y
r = 0
for i in range(2**n):
    s = bin(i)
    t = s[2:]
    t = t.rjust(n, "0")
    c = 1
    for j in range(n):
        if t[j] == "0":
            continue
        else:
            for p in range(n):
                if int(t[p]) == a[j][p] or a[j][p] == -1:
                    continue
                else:
                    c = 0
                    break
    if c:
        r = max(r, sum(map(int, list(t))))
print(r)

n = int(eval(input()))
a = []
for i in range(n):
    a_ = int(eval(input()))
    a.append([list(map(int, input().split())) for _ in range(a_)])
result = [0]
for i in range(1, 2**n):
    h = format(i, "0" + str(n) + "b")
    c = [int(j) for j in list(h)]
    checker = True
    for j in range(n):
        if c[j]:
            for x, y in a[j]:
                if c[x - 1] != y:
                    checker = False
                    break
    if checker:
        result.append(c.count(1))
print((max(result)))

-import sys - -a = [[-1 for _ in range(n)] for _ in range(n)] +a = [] -    j = int(eval(input())) -    for s in range(j): -        x, y = list(map(int, input().split())) -        a[i][x - 1] = y -r = 0 -for i in range(2**n): -    s = bin(i) -    t = s[2:] -    t = t.rjust(n, "0") -    c = 1 +    a_ = int(eval(input())) +    a.append([list(map(int, input().split())) for _ in range(a_)]) +result = [0] +for i in range(1, 2**n): +    h = format(i, "0" + str(n) + "b") +    c = [int(j) for j in list(h)] +    checker = True -        if t[j] == "0": -            continue -        else: -            for p in range(n): -                if int(t[p]) == a[j][p] or a[j][p] == -1: -                    continue -                else: -                    c = 0 +        if c[j]: +            for x, y in a[j]: +                if c[x - 1] != y: +                    checker = False -    if c: -        r = max(r, sum(map(int, list(t)))) -print(r) +    if checker: +        result.append(c.count(1)) +print((max(result)))