N = int(eval(input()))

msg = [[] for _ in range(N)]

for i in range(N):

    ai = int(eval(input()))

    for _ in range(ai):

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

        msg[i].append([x - 1, y])



ans = 0

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

    is_ok = True

    for j in range(N):

        if (i >> j) & 1 == 1:

            for x, y in msg[j]:

                if (i >> x) & 1 != y:

                    is_ok = False

                    break

    if is_ok:

        ans = max(ans, bin(i)[2:].count('1'))

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

t = [[] for _ in range(n)]



for i in range(n):

    a = int(eval(input()))

    for _ in range(a):

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

        x -= 1

        t[i].append([x, y])



ans = 0

for p in range(1 << n):

    cnt = 0

    is_not = False

    for i in range(n):

        if p >> i & 1:

            cnt += 1

            for ti in t[i]:

                x, y = ti

                if (p >> x & 1) != y:

                    is_not = True

                    cnt = 0

                    break

        if is_not:

            break

    ans = max(ans, cnt)

print(ans)

N = int(eval(input()))
msg = [[] for _ in range(N)]
for i in range(N):
    ai = int(eval(input()))
    for _ in range(ai):
        x, y = list(map(int, input().split()))
        msg[i].append([x - 1, y])
ans = 0
for i in range(1, 2**N):
    is_ok = True
    for j in range(N):
        if (i >> j) & 1 == 1:
            for x, y in msg[j]:
                if (i >> x) & 1 != y:
                    is_ok = False
                    break
    if is_ok:
        ans = max(ans, bin(i)[2:].count("1"))
print(ans)

n = int(eval(input()))
t = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for _ in range(a):
        x, y = list(map(int, input().split()))
        x -= 1
        t[i].append([x, y])
ans = 0
for p in range(1 << n):
    cnt = 0
    is_not = False
    for i in range(n):
        if p >> i & 1:
            cnt += 1
            for ti in t[i]:
                x, y = ti
                if (p >> x & 1) != y:
                    is_not = True
                    cnt = 0
                    break
        if is_not:
            break
    ans = max(ans, cnt)
print(ans)

-N = int(eval(input())) -msg = [[] for _ in range(N)] -for i in range(N): -    ai = int(eval(input())) -    for _ in range(ai): +n = int(eval(input())) +t = [[] for _ in range(n)] +for i in range(n): +    a = int(eval(input())) +    for _ in range(a): -        msg[i].append([x - 1, y]) +        x -= 1 +        t[i].append([x, y]) -for i in range(1, 2**N): -    is_ok = True -    for j in range(N): -        if (i >> j) & 1 == 1: -            for x, y in msg[j]: -                if (i >> x) & 1 != y: -                    is_ok = False +for p in range(1 << n): +    cnt = 0 +    is_not = False +    for i in range(n): +        if p >> i & 1: +            cnt += 1 +            for ti in t[i]: +                x, y = ti +                if (p >> x & 1) != y: +                    is_not = True +                    cnt = 0 -    if is_ok: -        ans = max(ans, bin(i)[2:].count("1")) +        if is_not: +            break +    ans = max(ans, cnt)