n = int(eval(input()))

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

ans = 0



for i in range(n):

    a = int(eval(input()))

    for j in range(a):

        xy = input().split()

        l[i].append(list(map(int, xy)))



for i in range(2**n):

    judge = True

    for j in range(n):

        if i & (1 << j): #証言者が正直者設定なら進む。

            for x, y in l[j]:

                if y == 0 and i & 1 << (x - 1): #証言:不親切 設定:親切

                    judge = False

                if y == 1 and i & 1 << (x - 1) == 0: #証言:正直、設定:不親切

                    judge = False

    if judge == True:

        cnt = bin(i).count("1")

        ans = max(ans, cnt)



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

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

ans = 0



for i in range(n):

    a = int(eval(input()))

    for j in range(a):

        xy = input().split()

        l[i].append(list(map(int, xy)))



for i in range(2**n):

    judge = True

    for j in range(n):

        if judge == False:

            break

        if i & (1 << j): #証言者が正直者設定なら進む。

            for x, y in l[j]:

                if y == 0 and i & 1 << (x - 1): #証言:不親切 設定:親切

                    judge = False

                if y == 1 and i & 1 << (x - 1) == 0: #証言:正直、設定:不親切

                    judge = False

    if judge == True:

        cnt = bin(i).count("1")

        ans = max(ans, cnt)



print(ans)
n = int(eval(input()))
l = [[] for _ in range(n)]
ans = 0
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        xy = input().split()
        l[i].append(list(map(int, xy)))
for i in range(2**n):
    judge = True
    for j in range(n):
        if i & (1 << j):  # 証言者が正直者設定なら進む。
            for x, y in l[j]:
                if y == 0 and i & 1 << (x - 1):  # 証言:不親切 設定:親切
                    judge = False
                if y == 1 and i & 1 << (x - 1) == 0:  # 証言:正直、設定:不親切
                    judge = False
    if judge == True:
        cnt = bin(i).count("1")
        ans = max(ans, cnt)
print(ans)

n = int(eval(input()))
l = [[] for _ in range(n)]
ans = 0
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        xy = input().split()
        l[i].append(list(map(int, xy)))
for i in range(2**n):
    judge = True
    for j in range(n):
        if judge == False:
            break
        if i & (1 << j):  # 証言者が正直者設定なら進む。
            for x, y in l[j]:
                if y == 0 and i & 1 << (x - 1):  # 証言:不親切 設定:親切
                    judge = False
                if y == 1 and i & 1 << (x - 1) == 0:  # 証言:正直、設定:不親切
                    judge = False
    if judge == True:
        cnt = bin(i).count("1")
        ans = max(ans, cnt)
print(ans)

+        if judge == False: +            break