from itertools import product

N = int(eval(input()))

said = [[-1] * (N+1) for _ in range(N+1)]



for a in range(N):

    K = int(eval(input()))

    for _ in range(K):

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

        said[a][x - 1] = y



ans = 0

for cand in product(list(range(2)), repeat=N):

    isOK = True



    for i, c in enumerate(cand):

        if not c:

            continue

        A = said[i]

        for j in range(N):

            if i == j or A[j] == -1:

                continue

            if cand[j] != A[j]:

                isOK = False

                break



    if isOK:

        ans = max(ans, sum(cand))



print(ans)

from itertools import product

import sys

input = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 7)



N = int(eval(input()))

mention = []

for _ in range(N):

    A = int(eval(input()))

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

    mention.append(xy)



ans = 0

for pair in product(list(range(2)), repeat=N):

    isOK = True

    for i, p in enumerate(pair):

        if not p:

            continue

        for x, y in mention[i]:

            if pair[x - 1] != y:

                isOK = False

    if isOK:

        ans = max(ans, sum(pair))



print(ans)
from itertools import product

N = int(eval(input()))
said = [[-1] * (N + 1) for _ in range(N + 1)]
for a in range(N):
    K = int(eval(input()))
    for _ in range(K):
        x, y = list(map(int, input().split()))
        said[a][x - 1] = y
ans = 0
for cand in product(list(range(2)), repeat=N):
    isOK = True
    for i, c in enumerate(cand):
        if not c:
            continue
        A = said[i]
        for j in range(N):
            if i == j or A[j] == -1:
                continue
            if cand[j] != A[j]:
                isOK = False
                break
    if isOK:
        ans = max(ans, sum(cand))
print(ans)

from itertools import product
import sys

input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
N = int(eval(input()))
mention = []
for _ in range(N):
    A = int(eval(input()))
    xy = [list(map(int, input().split())) for _ in range(A)]
    mention.append(xy)
ans = 0
for pair in product(list(range(2)), repeat=N):
    isOK = True
    for i, p in enumerate(pair):
        if not p:
            continue
        for x, y in mention[i]:
            if pair[x - 1] != y:
                isOK = False
    if isOK:
        ans = max(ans, sum(pair))
print(ans)

+import sys +input = sys.stdin.buffer.readline +sys.setrecursionlimit(10**7) -said = [[-1] * (N + 1) for _ in range(N + 1)] -for a in range(N): -    K = int(eval(input())) -    for _ in range(K): -        x, y = list(map(int, input().split())) -        said[a][x - 1] = y +mention = [] +for _ in range(N): +    A = int(eval(input())) +    xy = [list(map(int, input().split())) for _ in range(A)] +    mention.append(xy) -for cand in product(list(range(2)), repeat=N): +for pair in product(list(range(2)), repeat=N): -    for i, c in enumerate(cand): -        if not c: +    for i, p in enumerate(pair): +        if not p: -        A = said[i] -        for j in range(N): -            if i == j or A[j] == -1: -                continue -            if cand[j] != A[j]: +        for x, y in mention[i]: +            if pair[x - 1] != y: -                break -        ans = max(ans, sum(cand)) +        ans = max(ans, sum(pair))