n = int(eval(input()))

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



for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

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



ans = 0

for i in range(1 << n):

    h = []

    for j in range(n):

        h.append(i & 1 << j != 0)

    b = True

    for j in range(n):

        if i & (1 << j) != 0:

            for k in l[j]:

                if (k[1] == 1) != h[k[0]]:

                    b = False

                    break

        if not b:

            break

    

    if b:

        x = 0

        for j in range(n):

            if i & 1 << j:

                x += 1

        ans = max(ans,x)



print(ans)

        

n = int(eval(input()))

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



for i in range(n):

    a = int(eval(input()))

    for j in range(a):

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

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



ans = 0

for i in range(1 << n):

    h = []

    for j in range(n):

        h.append(i & 1 << j != 0)

    b = True

    for j in range(n):

        if i & 1 << j:

            for k in l[j]:

                if (k[1] == 1) != h[k[0]]:

                    b = False

                    break

        if not b:

            break

    if b:

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



print(ans)

n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, (input().split())))
        l[i].append([x - 1, y])
ans = 0
for i in range(1 << n):
    h = []
    for j in range(n):
        h.append(i & 1 << j != 0)
    b = True
    for j in range(n):
        if i & (1 << j) != 0:
            for k in l[j]:
                if (k[1] == 1) != h[k[0]]:
                    b = False
                    break
        if not b:
            break
    if b:
        x = 0
        for j in range(n):
            if i & 1 << j:
                x += 1
        ans = max(ans, x)
print(ans)

n = int(eval(input()))
l = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, (input().split())))
        l[i].append([x - 1, y])
ans = 0
for i in range(1 << n):
    h = []
    for j in range(n):
        h.append(i & 1 << j != 0)
    b = True
    for j in range(n):
        if i & 1 << j:
            for k in l[j]:
                if (k[1] == 1) != h[k[0]]:
                    b = False
                    break
        if not b:
            break
    if b:
        ans = max(ans, h.count(True))
print(ans)

-        if i & (1 << j) != 0: +        if i & 1 << j: -        x = 0 -        for j in range(n): -            if i & 1 << j: -                x += 1 -        ans = max(ans, x) +        ans = max(ans, h.count(True))