N = int(eval(input()))



# 証言者ごとに整理する

testimony_list = []

for i in range(N):

    array = [-1] * N

    testimony_list.append(array)

for i in range(N):

    A = int(eval(input()))

    for j in range(A):

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

        # iさんの、xさんへの証言

        testimony_list[i][x - 1] = y



max_count = 0

for i in range(2 ** N):

    failed = False

    for j in range(N):

        if not (i >> j & 1):

            continue

        array = testimony_list[j]

        for k in range(N):

            if array[k] != -1 and (i >> k & 1) != array[k]:

                failed = True

                break

    if failed is False:

        max_count = max(max_count, bin(i)[2:].count("1"))

print(max_count)

N = int(eval(input()))



# 証言者ごとに整理する

testimony_list = []

for i in range(N):

    array = [-1] * N

    testimony_list.append(array)

for i in range(N):

    A = int(eval(input()))

    for j in range(A):

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

        # iさんの、xさんへの証言

        testimony_list[i][x - 1] = y



max_count = 0

for i in range(2 ** N):

    failed = False

    for j in range(N):

        if not (i >> j & 1):

            continue

        array = testimony_list[j]

        for k in range(N):

            if array[k] == -1:

                continue

            if (i >> k & 1) != array[k]:  # 正直者に対して不親切 or 不親切に対して正直者と証言

                failed = True

                break

    if not failed:

        # 「0b010110」の「0b」を除外して1の数をカウント

        max_count = max(max_count, bin(i)[2:].count("1"))

print(max_count)

N = int(eval(input()))
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
    array = [-1] * N
    testimony_list.append(array)
for i in range(N):
    A = int(eval(input()))
    for j in range(A):
        x, y = list(map(int, input().split()))
        # iさんの、xさんへの証言
        testimony_list[i][x - 1] = y
max_count = 0
for i in range(2**N):
    failed = False
    for j in range(N):
        if not (i >> j & 1):
            continue
        array = testimony_list[j]
        for k in range(N):
            if array[k] != -1 and (i >> k & 1) != array[k]:
                failed = True
                break
    if failed is False:
        max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)

N = int(eval(input()))
# 証言者ごとに整理する
testimony_list = []
for i in range(N):
    array = [-1] * N
    testimony_list.append(array)
for i in range(N):
    A = int(eval(input()))
    for j in range(A):
        x, y = list(map(int, input().split()))
        # iさんの、xさんへの証言
        testimony_list[i][x - 1] = y
max_count = 0
for i in range(2**N):
    failed = False
    for j in range(N):
        if not (i >> j & 1):
            continue
        array = testimony_list[j]
        for k in range(N):
            if array[k] == -1:
                continue
            if (i >> k & 1) != array[k]:  # 正直者に対して不親切 or 不親切に対して正直者と証言
                failed = True
                break
    if not failed:
        # 「0b010110」の「0b」を除外して1の数をカウント
        max_count = max(max_count, bin(i)[2:].count("1"))
print(max_count)

-            if array[k] != -1 and (i >> k & 1) != array[k]: +            if array[k] == -1: +                continue +            if (i >> k & 1) != array[k]:  # 正直者に対して不親切 or 不親切に対して正直者と証言 -    if failed is False: +    if not failed: +        # 「0b010110」の「0b」を除外して1の数をカウント