N = int(eval(input()))



# print("")

# 証言者ごとに整理する

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):

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

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

        # print("test:{} {}".format(x, y))

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

        # print("test:{} {} {}".format(x - 1, i, y))

        # print(testimony_list)

        testimony_list[i][x - 1] = y



# print(testimony_list)

max_count = 0

failed = False

for i in range(2 ** N):

    results = [-1] * N

    shoujiki = 0

    for j in range(len(testimony_list)):

        # check = (i >> j & 1)

        # print("チェック: {} {}".format(i, j))

        # print(i >> j & 1)

        if i >> j & 1:

            shoujiki += 1

            # print("{}:{}".format(bin(i), j))

            array = testimony_list[j]

            for k in range(len(array)):

                # print(

                #     "k={} result[k]:array[k] {}:{}".format(

                #         k, results[k], array[k]))

                # print(i >> k & 1)

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

                    # print("矛盾2")

                    failed = True

                    break

                elif (i >> k & 1) and array[k] == 0:

                    # print("矛盾3")

                    failed = True

                    break

                if array[k] == -1:

                    continue

                if results[k] == -1:

                    results[k] = array[k]

                elif results[k] != array[k]:

                    # print("矛盾1")

                    failed = True

                    break

        if failed is True:

            # print("failed")

            # results = [-1] * N

            break

    if failed is True:

        failed = False

        continue

    # print("計算: {}".format(i))

    # print(results)

    # count = 0

    # for result in results:

    #     if result != -1:

    #         count += 1

    # print(count)

    if max_count < shoujiki:

        max_count = shoujiki

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()))
# print("")
# 証言者ごとに整理する
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):
        # iさんの、xさんへの証言
        x, y = list(map(int, input().split()))
        # print("test:{} {}".format(x, y))
        # iさんの、xさんへの証言
        # print("test:{} {} {}".format(x - 1, i, y))
        # print(testimony_list)
        testimony_list[i][x - 1] = y
# print(testimony_list)
max_count = 0
failed = False
for i in range(2**N):
    results = [-1] * N
    shoujiki = 0
    for j in range(len(testimony_list)):
        # check = (i >> j & 1)
        # print("チェック: {} {}".format(i, j))
        # print(i >> j & 1)
        if i >> j & 1:
            shoujiki += 1
            # print("{}:{}".format(bin(i), j))
            array = testimony_list[j]
            for k in range(len(array)):
                # print(
                #     "k={} result[k]:array[k] {}:{}".format(
                #         k, results[k], array[k]))
                # print(i >> k & 1)
                if not (i >> k & 1) and array[k] == 1:
                    # print("矛盾2")
                    failed = True
                    break
                elif (i >> k & 1) and array[k] == 0:
                    # print("矛盾3")
                    failed = True
                    break
                if array[k] == -1:
                    continue
                if results[k] == -1:
                    results[k] = array[k]
                elif results[k] != array[k]:
                    # print("矛盾1")
                    failed = True
                    break
        if failed is True:
            # print("failed")
            # results = [-1] * N
            break
    if failed is True:
        failed = False
        continue
    # print("計算: {}".format(i))
    # print(results)
    # count = 0
    # for result in results:
    #     if result != -1:
    #         count += 1
    # print(count)
    if max_count < shoujiki:
        max_count = shoujiki
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)

-# print("") +        x, y = list(map(int, input().split())) -        x, y = list(map(int, input().split())) -        # print("test:{} {}".format(x, y)) -        # iさんの、xさんへの証言 -        # print("test:{} {} {}".format(x - 1, i, y)) -        # print(testimony_list) -# print(testimony_list) -failed = False -    results = [-1] * N -    shoujiki = 0 -    for j in range(len(testimony_list)): -        # check = (i >> j & 1) -        # print("チェック: {} {}".format(i, j)) -        # print(i >> j & 1) -        if i >> j & 1: -            shoujiki += 1 -            # print("{}:{}".format(bin(i), j)) -            array = testimony_list[j] -            for k in range(len(array)): -                # print( -                #     "k={} result[k]:array[k] {}:{}".format( -                #         k, results[k], array[k])) -                # print(i >> k & 1) -                if not (i >> k & 1) and array[k] == 1: -                    # print("矛盾2") -                    failed = True -                    break -                elif (i >> k & 1) and array[k] == 0: -                    # print("矛盾3") -                    failed = True -                    break -                if array[k] == -1: -                    continue -                if results[k] == -1: -                    results[k] = array[k] -                elif results[k] != array[k]: -                    # print("矛盾1") -                    failed = True -                    break -        if failed is True: -            # print("failed") -            # results = [-1] * N -            break -    if failed is True: -        failed = False -        continue -    # print("計算: {}".format(i)) -    # print(results) -    # count = 0 -    # for result in results: -    #     if result != -1: -    #         count += 1 -    # print(count) -    if max_count < shoujiki: -        max_count = shoujiki +    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"))