from itertools import product

def trueCheck(i,x):

    for j in range(1,N+1):

        if B[i][j]==1:

            if x[j-1]==0:

                return 1

        elif B[i][j]==0:

            if x[j-1]==1:

                return 1

    return 0

N = int(eval(input()))

A = [0]

B = {i:[-1 for _ in range(N+1)] for i in range(1,N+1)}

for i in range(1,N+1):

    A.append(int(eval(input())))

    for _ in range(A[-1]):

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

        B[i][x] = y

cmax = 0

for z in product([0,1],repeat=N):

    flag = 0

    for i in range(1,N+1):

        if z[i-1]==1:

            flag = trueCheck(i,z)            

        if flag==1:break

    if flag==0:

        cmax = max(cmax,sum(z))

print(cmax)               
from itertools import product

N = int(eval(input()))

G = {i:[] for i in range(1,N+1)}

for i in range(1,N+1):

    K = int(eval(input()))

    for j in range(K):

        G[i].append(list(map(int,input().split())))

cmax = 0

for z in product((0,1),repeat=N):

    flag = 0

    for i in range(N):

        if z[i]==1:

            ind = i+1

            for [x,y] in G[ind]:

                if z[x-1]==y:continue

                else:

                    flag=1

                    break

            if flag==1:

                break

    if flag==0:

        cmax = max(cmax,sum(z))

print(cmax)
from itertools import product


def trueCheck(i, x):
    for j in range(1, N + 1):
        if B[i][j] == 1:
            if x[j - 1] == 0:
                return 1
        elif B[i][j] == 0:
            if x[j - 1] == 1:
                return 1
    return 0


N = int(eval(input()))
A = [0]
B = {i: [-1 for _ in range(N + 1)] for i in range(1, N + 1)}
for i in range(1, N + 1):
    A.append(int(eval(input())))
    for _ in range(A[-1]):
        x, y = list(map(int, input().split()))
        B[i][x] = y
cmax = 0
for z in product([0, 1], repeat=N):
    flag = 0
    for i in range(1, N + 1):
        if z[i - 1] == 1:
            flag = trueCheck(i, z)
        if flag == 1:
            break
    if flag == 0:
        cmax = max(cmax, sum(z))
print(cmax)

from itertools import product

N = int(eval(input()))
G = {i: [] for i in range(1, N + 1)}
for i in range(1, N + 1):
    K = int(eval(input()))
    for j in range(K):
        G[i].append(list(map(int, input().split())))
cmax = 0
for z in product((0, 1), repeat=N):
    flag = 0
    for i in range(N):
        if z[i] == 1:
            ind = i + 1
            for [x, y] in G[ind]:
                if z[x - 1] == y:
                    continue
                else:
                    flag = 1
                    break
            if flag == 1:
                break
    if flag == 0:
        cmax = max(cmax, sum(z))
print(cmax)

- -def trueCheck(i, x): -    for j in range(1, N + 1): -        if B[i][j] == 1: -            if x[j - 1] == 0: -                return 1 -        elif B[i][j] == 0: -            if x[j - 1] == 1: -                return 1 -    return 0 - - -A = [0] -B = {i: [-1 for _ in range(N + 1)] for i in range(1, N + 1)} +G = {i: [] for i in range(1, N + 1)} -    A.append(int(eval(input()))) -    for _ in range(A[-1]): -        x, y = list(map(int, input().split())) -        B[i][x] = y +    K = int(eval(input())) +    for j in range(K): +        G[i].append(list(map(int, input().split()))) -for z in product([0, 1], repeat=N): +for z in product((0, 1), repeat=N): -    for i in range(1, N + 1): -        if z[i - 1] == 1: -            flag = trueCheck(i, z) -        if flag == 1: -            break +    for i in range(N): +        if z[i] == 1: +            ind = i + 1 +            for [x, y] in G[ind]: +                if z[x - 1] == y: +                    continue +                else: +                    flag = 1 +                    break +            if flag == 1: +                break