n = int(eval(input()))

a_list = []

xy_list = []

for i in range(n):

    A = int(eval(input()))

    a_list.append(A)

    xy = [list(map(int, input().split())) for _ in range(A)]

    xy_list.append(xy)



ans = 0



for i in range(2**n):

    flag = True

    for j in range(n):  # 人ｊについて

        if (i >> j) & 1 == 1:  # 人jが正直ならば

            for k in range(a_list[j]):  # 人jの証言kについて

                if xy_list[j][k][1] == 1:

                    m = xy_list[j][k][0]

                    if (i >> m-1) & 1 != 1:  # 矛盾発生（正直者のjの証言で正直者と確定したｍが不親切だった）

                        flag = False

                        break



                elif xy_list[j][k][1] == 0:

                    m = xy_list[j][k][0]

                    if (i >> m-1) & 1 == 1:

                        flag = False

                        break

    if flag:

        i_bin = format(i, 'b')

        if ans < i_bin.count('1'):

            ans = i_bin.count('1')



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

a = [0]*n

xy = [0]*n

for i in range(n):

    a[i] = int(eval(input()))

    xy[i] = [list(map(int, input().split())) for _ in range(a[i])]



ans = 0

for i in range(2**n):

    flag = True

    for j in range(n):

        if i >> j & 1 == 1:  # 右からｊ番目の人は正直もの

            for k in range(a[j]):

                if xy[j][k][1] == 1 and i >> (xy[j][k][0]-1) & 1 != 1:

                    flag = False

                    break

                elif xy[j][k][1] == 0 and i >> (xy[j][k][0]-1) & 1 != 0:

                    flag = False

                    break

            else:

                continue

            break

    if flag and ans < str(bin(i)).count("1"):

        ans = str(bin(i)).count("1")





print(ans)
n = int(eval(input()))
a_list = []
xy_list = []
for i in range(n):
    A = int(eval(input()))
    a_list.append(A)
    xy = [list(map(int, input().split())) for _ in range(A)]
    xy_list.append(xy)
ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):  # 人ｊについて
        if (i >> j) & 1 == 1:  # 人jが正直ならば
            for k in range(a_list[j]):  # 人jの証言kについて
                if xy_list[j][k][1] == 1:
                    m = xy_list[j][k][0]
                    if (i >> m - 1) & 1 != 1:  # 矛盾発生（正直者のjの証言で正直者と確定したｍが不親切だった）
                        flag = False
                        break
                elif xy_list[j][k][1] == 0:
                    m = xy_list[j][k][0]
                    if (i >> m - 1) & 1 == 1:
                        flag = False
                        break
    if flag:
        i_bin = format(i, "b")
        if ans < i_bin.count("1"):
            ans = i_bin.count("1")
print(ans)

n = int(eval(input()))
a = [0] * n
xy = [0] * n
for i in range(n):
    a[i] = int(eval(input()))
    xy[i] = [list(map(int, input().split())) for _ in range(a[i])]
ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if i >> j & 1 == 1:  # 右からｊ番目の人は正直もの
            for k in range(a[j]):
                if xy[j][k][1] == 1 and i >> (xy[j][k][0] - 1) & 1 != 1:
                    flag = False
                    break
                elif xy[j][k][1] == 0 and i >> (xy[j][k][0] - 1) & 1 != 0:
                    flag = False
                    break
            else:
                continue
            break
    if flag and ans < str(bin(i)).count("1"):
        ans = str(bin(i)).count("1")
print(ans)

-a_list = [] -xy_list = [] +a = [0] * n +xy = [0] * n -    A = int(eval(input())) -    a_list.append(A) -    xy = [list(map(int, input().split())) for _ in range(A)] -    xy_list.append(xy) +    a[i] = int(eval(input())) +    xy[i] = [list(map(int, input().split())) for _ in range(a[i])] -    for j in range(n):  # 人ｊについて -        if (i >> j) & 1 == 1:  # 人jが正直ならば -            for k in range(a_list[j]):  # 人jの証言kについて -                if xy_list[j][k][1] == 1: -                    m = xy_list[j][k][0] -                    if (i >> m - 1) & 1 != 1:  # 矛盾発生（正直者のjの証言で正直者と確定したｍが不親切だった） -                        flag = False -                        break -                elif xy_list[j][k][1] == 0: -                    m = xy_list[j][k][0] -                    if (i >> m - 1) & 1 == 1: -                        flag = False -                        break -    if flag: -        i_bin = format(i, "b") -        if ans < i_bin.count("1"): -            ans = i_bin.count("1") +    for j in range(n): +        if i >> j & 1 == 1:  # 右からｊ番目の人は正直もの +            for k in range(a[j]): +                if xy[j][k][1] == 1 and i >> (xy[j][k][0] - 1) & 1 != 1: +                    flag = False +                    break +                elif xy[j][k][1] == 0 and i >> (xy[j][k][0] - 1) & 1 != 0: +                    flag = False +                    break +            else: +                continue +            break +    if flag and ans < str(bin(i)).count("1"): +        ans = str(bin(i)).count("1")