N = int(eval(input()))

xy = [[] for _ in range(N)]

for i in range(N):

    A = int(eval(input()))

    for _ in range(A):

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

        xy[i].append([x-1,y])



answer = 0

# 状態n

for n in range(2 ** N):

    # 正直者のリスト

    true_person = []

    index = 0

    copy_n = n

    while copy_n:

        if copy_n & 1:

            true_person.append(index)

        index += 1

        copy_n >>= 1



    # 矛盾が生じたときTrue

    flag = False



    # 人i

    for i in true_person:

        # iさんの証言

        for x,y in xy[i]:

            # 証言と状態が違う場合

            if (x in true_person and y == 0) or (not(x in true_person) and y == 1):

                flag = True

        if flag:

            break

    if flag:

        continue

    else:

        answer = max(answer, len(true_person))

    

print(answer)
N = int(eval(input()))

edge = [[] for _ in range(N)]

for i in range(N):

    A = int(eval(input()))

    for j in range(A):

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

        edge[i].append((x-1,y))



ans = 0

for i in range(2**N):

    # 1: 正直者

    state = [0] * N

    for j in range(N):

        state[j] = (i >> j) & 1

    

    # 真偽を確かめる

    flag = True

    for j in range(N):

        if state[j] == 0:

            continue

        for x,y in edge[j]:

            if state[x] == y:

                continue

            flag = False

            break

        if not flag:

            break

    if not flag:

        continue



    ans = max(ans, state.count(1))



print(ans)
N = int(eval(input()))
xy = [[] for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        xy[i].append([x - 1, y])
answer = 0
# 状態n
for n in range(2**N):
    # 正直者のリスト
    true_person = []
    index = 0
    copy_n = n
    while copy_n:
        if copy_n & 1:
            true_person.append(index)
        index += 1
        copy_n >>= 1
    # 矛盾が生じたときTrue
    flag = False
    # 人i
    for i in true_person:
        # iさんの証言
        for x, y in xy[i]:
            # 証言と状態が違う場合
            if (x in true_person and y == 0) or (not (x in true_person) and y == 1):
                flag = True
        if flag:
            break
    if flag:
        continue
    else:
        answer = max(answer, len(true_person))
print(answer)

N = int(eval(input()))
edge = [[] for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for j in range(A):
        x, y = list(map(int, input().split()))
        edge[i].append((x - 1, y))
ans = 0
for i in range(2**N):
    # 1: 正直者
    state = [0] * N
    for j in range(N):
        state[j] = (i >> j) & 1
    # 真偽を確かめる
    flag = True
    for j in range(N):
        if state[j] == 0:
            continue
        for x, y in edge[j]:
            if state[x] == y:
                continue
            flag = False
            break
        if not flag:
            break
    if not flag:
        continue
    ans = max(ans, state.count(1))
print(ans)

-xy = [[] for _ in range(N)] +edge = [[] for _ in range(N)] -    for _ in range(A): +    for j in range(A): -        xy[i].append([x - 1, y]) -answer = 0 -# 状態n -for n in range(2**N): -    # 正直者のリスト -    true_person = [] -    index = 0 -    copy_n = n -    while copy_n: -        if copy_n & 1: -            true_person.append(index) -        index += 1 -        copy_n >>= 1 -    # 矛盾が生じたときTrue -    flag = False -    # 人i -    for i in true_person: -        # iさんの証言 -        for x, y in xy[i]: -            # 証言と状態が違う場合 -            if (x in true_person and y == 0) or (not (x in true_person) and y == 1): -                flag = True -        if flag: +        edge[i].append((x - 1, y)) +ans = 0 +for i in range(2**N): +    # 1: 正直者 +    state = [0] * N +    for j in range(N): +        state[j] = (i >> j) & 1 +    # 真偽を確かめる +    flag = True +    for j in range(N): +        if state[j] == 0: +            continue +        for x, y in edge[j]: +            if state[x] == y: +                continue +            flag = False -    if flag: +        if not flag: +            break +    if not flag: -    else: -        answer = max(answer, len(true_person)) -print(answer) +    ans = max(ans, state.count(1)) +print(ans)