from itertools import product



n = int(eval(input()))



a = []

xy = []



for _ in range(n):

    a_tmp = int(eval(input()))

    a.append(a_tmp)

    xy_tmp = []

    for _ in range(a_tmp):

        xy_tmp.append(list(map(int, input().split())))

    xy.append(xy_tmp)



ans = 0

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

    sat = True

    for i, bl in enumerate(pat):

        if bl:

            for x, y in xy[i]:

                x -= 1

                if pat[x] != y:

                    sat = False



    if sat:

        cnt = sum(pat)

        ans = max(ans, cnt)



print(ans)

from itertools import product



n = int(eval(input()))

a = []

xy = []



for _ in range(n):

    ea = int(eval(input()))

    new = []

    for _ in range(ea):

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

        x -= 1

        new.append([x, y])



    xy.append(new)



ans = 0

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

    bl = True

    for i, e in enumerate(pat):

        if e:

            for x, y in xy[i]:

                if pat[x] != y:

                    bl = False



    if bl:

        ans = max(ans, sum(pat))



print(ans)

from itertools import product

n = int(eval(input()))
a = []
xy = []
for _ in range(n):
    a_tmp = int(eval(input()))
    a.append(a_tmp)
    xy_tmp = []
    for _ in range(a_tmp):
        xy_tmp.append(list(map(int, input().split())))
    xy.append(xy_tmp)
ans = 0
for pat in product([1, 0], repeat=n):
    sat = True
    for i, bl in enumerate(pat):
        if bl:
            for x, y in xy[i]:
                x -= 1
                if pat[x] != y:
                    sat = False
    if sat:
        cnt = sum(pat)
        ans = max(ans, cnt)
print(ans)

from itertools import product

n = int(eval(input()))
a = []
xy = []
for _ in range(n):
    ea = int(eval(input()))
    new = []
    for _ in range(ea):
        x, y = list(map(int, input().split()))
        x -= 1
        new.append([x, y])
    xy.append(new)
ans = 0
for pat in product([1, 0], repeat=n):
    bl = True
    for i, e in enumerate(pat):
        if e:
            for x, y in xy[i]:
                if pat[x] != y:
                    bl = False
    if bl:
        ans = max(ans, sum(pat))
print(ans)

-    a_tmp = int(eval(input())) -    a.append(a_tmp) -    xy_tmp = [] -    for _ in range(a_tmp): -        xy_tmp.append(list(map(int, input().split()))) -    xy.append(xy_tmp) +    ea = int(eval(input())) +    new = [] +    for _ in range(ea): +        x, y = list(map(int, input().split())) +        x -= 1 +        new.append([x, y]) +    xy.append(new) -    sat = True -    for i, bl in enumerate(pat): -        if bl: +    bl = True +    for i, e in enumerate(pat): +        if e: -                x -= 1 -                    sat = False -    if sat: -        cnt = sum(pat) -        ans = max(ans, cnt) +                    bl = False +    if bl: +        ans = max(ans, sum(pat))