N = int(eval(input()))



M = []

for _ in range(N):

    A = int(eval(input()))

    state = []

    for _ in range(A):

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

        x -= 1

        state.append((x, y))

    M.append(state)



ans = 0

for mask in range(1 << N):

    can = True

    for i, s in enumerate(M):

        if (mask & (1 << i)) != 0:

            for x, y in s:

                v = 1 if (mask & (1 << x)) != 0 else 0

                if v != y:

                    can = False

                    break

    if can:

        cnt = 0

        for i in range(N):

            if (mask & (1 << i)) != 0:

                cnt += 1

        ans = max(ans, cnt)



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



S = []

for _ in range(N):

    A = int(eval(input()))

    S.append([tuple(map(int, input().split())) for _ in range(A)])



def sol(state):

    for i, A in enumerate(S):

        if (state & (1 << i)) == 0:

            continue

        for j, s in A:

            if ((state & (1 << (j - 1))) != 0) != (s != 0):

                return 0

    return sum(map(int, bin(state)[2:]))



ans = 0

for state in range(1 << N):

    ans = max(ans, sol(state))

print(ans)

N = int(eval(input()))
M = []
for _ in range(N):
    A = int(eval(input()))
    state = []
    for _ in range(A):
        x, y = list(map(int, input().split()))
        x -= 1
        state.append((x, y))
    M.append(state)
ans = 0
for mask in range(1 << N):
    can = True
    for i, s in enumerate(M):
        if (mask & (1 << i)) != 0:
            for x, y in s:
                v = 1 if (mask & (1 << x)) != 0 else 0
                if v != y:
                    can = False
                    break
    if can:
        cnt = 0
        for i in range(N):
            if (mask & (1 << i)) != 0:
                cnt += 1
        ans = max(ans, cnt)
print(ans)

N = int(eval(input()))
S = []
for _ in range(N):
    A = int(eval(input()))
    S.append([tuple(map(int, input().split())) for _ in range(A)])


def sol(state):
    for i, A in enumerate(S):
        if (state & (1 << i)) == 0:
            continue
        for j, s in A:
            if ((state & (1 << (j - 1))) != 0) != (s != 0):
                return 0
    return sum(map(int, bin(state)[2:]))


ans = 0
for state in range(1 << N):
    ans = max(ans, sol(state))
print(ans)

-M = [] +S = [] -    state = [] -    for _ in range(A): -        x, y = list(map(int, input().split())) -        x -= 1 -        state.append((x, y)) -    M.append(state) +    S.append([tuple(map(int, input().split())) for _ in range(A)]) + + +def sol(state): +    for i, A in enumerate(S): +        if (state & (1 << i)) == 0: +            continue +        for j, s in A: +            if ((state & (1 << (j - 1))) != 0) != (s != 0): +                return 0 +    return sum(map(int, bin(state)[2:])) + + -for mask in range(1 << N): -    can = True -    for i, s in enumerate(M): -        if (mask & (1 << i)) != 0: -            for x, y in s: -                v = 1 if (mask & (1 << x)) != 0 else 0 -                if v != y: -                    can = False -                    break -    if can: -        cnt = 0 -        for i in range(N): -            if (mask & (1 << i)) != 0: -                cnt += 1 -        ans = max(ans, cnt) +for state in range(1 << N): +    ans = max(ans, sol(state))