n = int(eval(input()))

hf = [[None] for i in range(n)]



for i in range(n):

    tmp = []

    for j in range(int(eval(input()))):

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

    hf[i] = tmp

ans = 0

for i in range(2 ** n):

    f = 0

    b = bin(i)[2:].zfill(n)

    for j in range(n):

        if b[j] == "0":

            continue

        else:

            for x, y in hf[j]:

                if b[x - 1] != str(y):

                    f = 1

    if f == 0:

        ans = max(ans, b.count("1"))

print(ans)
def cnt_honest(bit):

    for i in range(n):

        if bit[i] == "1":

            for x, y in hf[i]:

                if bit[x - 1] != str(y):

                    return 0

    return bit.count("1")





n = int(eval(input()))

hf = [[] for i in range(n)]



for i in range(n):

    for j in range(int(eval(input()))):

        hf[i].append(list(map(int, input().split())))



ans = 0

for i in range(2 ** n):

    ans = max(ans, cnt_honest(format(i, "b").zfill(n)))

print(ans)
n = int(eval(input()))
hf = [[None] for i in range(n)]
for i in range(n):
    tmp = []
    for j in range(int(eval(input()))):
        tmp.append(list(map(int, input().split())))
    hf[i] = tmp
ans = 0
for i in range(2**n):
    f = 0
    b = bin(i)[2:].zfill(n)
    for j in range(n):
        if b[j] == "0":
            continue
        else:
            for x, y in hf[j]:
                if b[x - 1] != str(y):
                    f = 1
    if f == 0:
        ans = max(ans, b.count("1"))
print(ans)

def cnt_honest(bit):
    for i in range(n):
        if bit[i] == "1":
            for x, y in hf[i]:
                if bit[x - 1] != str(y):
                    return 0
    return bit.count("1")


n = int(eval(input()))
hf = [[] for i in range(n)]
for i in range(n):
    for j in range(int(eval(input()))):
        hf[i].append(list(map(int, input().split())))
ans = 0
for i in range(2**n):
    ans = max(ans, cnt_honest(format(i, "b").zfill(n)))
print(ans)

+def cnt_honest(bit): +    for i in range(n): +        if bit[i] == "1": +            for x, y in hf[i]: +                if bit[x - 1] != str(y): +                    return 0 +    return bit.count("1") + + -hf = [[None] for i in range(n)] +hf = [[] for i in range(n)] -    tmp = [] -        tmp.append(list(map(int, input().split()))) -    hf[i] = tmp +        hf[i].append(list(map(int, input().split()))) -    f = 0 -    b = bin(i)[2:].zfill(n) -    for j in range(n): -        if b[j] == "0": -            continue -        else: -            for x, y in hf[j]: -                if b[x - 1] != str(y): -                    f = 1 -    if f == 0: -        ans = max(ans, b.count("1")) +    ans = max(ans, cnt_honest(format(i, "b").zfill(n)))