N = int(eval(input()))

a = [[] for i in range(N)]

ans = 0

for i in range(N):

    times = int(eval(input()))

    for j in range(times):

        a[i].append(tuple(map(int, input().split())))



for i in range(2 ** N):

    flag2 = False

    cnt = 0

    flag = [0] * N

    for j in range(N):

        if (i >> j) & 1:

            flag[j] = 1

    for k in range(N):

        if flag[k] == 1:

            for m in range(len(a[k])):

                x, y = a[k][m]

                if flag[x - 1] != y:

                    flag2 = True

                    break

        if flag2:

            break

        if k == N - 1:

            cnt = flag.count(1)



    ans = max(ans, cnt)

print(ans)

n = int(eval(input()))

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

for i in range(n):

    ai = int(eval(input()))

    for _ in range(ai):

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

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

ans = 0

for i in range(2 ** n):

    f = [False] * n

    flag = False

    for j in range(n):

        if i >> j & 1:

            f[j] = True

    for j in range(n):

        if f[j]:

            for x, y in witness[j]:

                if f[x] and y == 0 or not f[x] and y == 1:

                    flag = True

                    break



        if flag:

            break

        if j == n - 1:

            ans = max(ans, f.count(True))

print(ans)
N = int(eval(input()))
a = [[] for i in range(N)]
ans = 0
for i in range(N):
    times = int(eval(input()))
    for j in range(times):
        a[i].append(tuple(map(int, input().split())))
for i in range(2**N):
    flag2 = False
    cnt = 0
    flag = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            flag[j] = 1
    for k in range(N):
        if flag[k] == 1:
            for m in range(len(a[k])):
                x, y = a[k][m]
                if flag[x - 1] != y:
                    flag2 = True
                    break
        if flag2:
            break
        if k == N - 1:
            cnt = flag.count(1)
    ans = max(ans, cnt)
print(ans)

n = int(eval(input()))
witness = [[] for _ in range(n)]
for i in range(n):
    ai = int(eval(input()))
    for _ in range(ai):
        x, y = list(map(int, input().split()))
        witness[i].append((x - 1, y))
ans = 0
for i in range(2**n):
    f = [False] * n
    flag = False
    for j in range(n):
        if i >> j & 1:
            f[j] = True
    for j in range(n):
        if f[j]:
            for x, y in witness[j]:
                if f[x] and y == 0 or not f[x] and y == 1:
                    flag = True
                    break
        if flag:
            break
        if j == n - 1:
            ans = max(ans, f.count(True))
print(ans)

-N = int(eval(input())) -a = [[] for i in range(N)] +n = int(eval(input())) +witness = [[] for _ in range(n)] +for i in range(n): +    ai = int(eval(input())) +    for _ in range(ai): +        x, y = list(map(int, input().split())) +        witness[i].append((x - 1, y)) -for i in range(N): -    times = int(eval(input())) -    for j in range(times): -        a[i].append(tuple(map(int, input().split()))) -for i in range(2**N): -    flag2 = False -    cnt = 0 -    flag = [0] * N -    for j in range(N): -        if (i >> j) & 1: -            flag[j] = 1 -    for k in range(N): -        if flag[k] == 1: -            for m in range(len(a[k])): -                x, y = a[k][m] -                if flag[x - 1] != y: -                    flag2 = True +for i in range(2**n): +    f = [False] * n +    flag = False +    for j in range(n): +        if i >> j & 1: +            f[j] = True +    for j in range(n): +        if f[j]: +            for x, y in witness[j]: +                if f[x] and y == 0 or not f[x] and y == 1: +                    flag = True -        if flag2: +        if flag: -        if k == N - 1: -            cnt = flag.count(1) -    ans = max(ans, cnt) +        if j == n - 1: +            ans = max(ans, f.count(True))