N = int(eval(input()))

xy = []

for i in range(N):

    A = int(eval(input()))

    xy.append([])

    for j in range(A):

        xy[i].append(tuple(map(int, input().split())))

 

ans = 0

 

for i in range(2 ** N):

    h = [0] * N

 

    for j in range(N):

        if (i >> j) & 1:

            h[j] = 1

    

    flag = False

    for i in range(N):

        if h[i] == 1:

            for x, y in xy[i]:

                if h[x-1] != y:

                    flag = True

                    break

            if flag:

                break

    

    if not flag:

        ans = max(ans, sum(h))

 

print(ans)
import itertools

 

N = int(eval(input()))

 

evidence_dit = {}

 

for i in range(N):

    A = int(eval(input()))

    x_y = []

    if A == 0:

        evidence_dit[i] = []

    for j in range(A):

        x_y.append(list(map(int,input().split())))

        

        evidence_dit[i] = x_y 



attribute = [0,1]

ans = 0

 

for i in itertools.product(attribute,repeat=N):

    flag = False

    

    for j in range(N):

       

        if i[j] == 1:

            for k in evidence_dit[j]:

                

                

                if i[k[0]-1] != k[1]:

                    flag = True

                    break

            if flag:

                break

 

    if flag == False:

        

        ans = max(ans,sum(i))

             

 

print(ans)

    
N = int(eval(input()))
xy = []
for i in range(N):
    A = int(eval(input()))
    xy.append([])
    for j in range(A):
        xy[i].append(tuple(map(int, input().split())))
ans = 0
for i in range(2**N):
    h = [0] * N
    for j in range(N):
        if (i >> j) & 1:
            h[j] = 1
    flag = False
    for i in range(N):
        if h[i] == 1:
            for x, y in xy[i]:
                if h[x - 1] != y:
                    flag = True
                    break
            if flag:
                break
    if not flag:
        ans = max(ans, sum(h))
print(ans)

import itertools

N = int(eval(input()))
evidence_dit = {}
for i in range(N):
    A = int(eval(input()))
    x_y = []
    if A == 0:
        evidence_dit[i] = []
    for j in range(A):
        x_y.append(list(map(int, input().split())))
        evidence_dit[i] = x_y
attribute = [0, 1]
ans = 0
for i in itertools.product(attribute, repeat=N):
    flag = False
    for j in range(N):
        if i[j] == 1:
            for k in evidence_dit[j]:
                if i[k[0] - 1] != k[1]:
                    flag = True
                    break
            if flag:
                break
    if flag == False:
        ans = max(ans, sum(i))
print(ans)

+import itertools + -xy = [] +evidence_dit = {} -    xy.append([]) +    x_y = [] +    if A == 0: +        evidence_dit[i] = [] -        xy[i].append(tuple(map(int, input().split()))) +        x_y.append(list(map(int, input().split()))) +        evidence_dit[i] = x_y +attribute = [0, 1] -for i in range(2**N): -    h = [0] * N +for i in itertools.product(attribute, repeat=N): +    flag = False -        if (i >> j) & 1: -            h[j] = 1 -    flag = False -    for i in range(N): -        if h[i] == 1: -            for x, y in xy[i]: -                if h[x - 1] != y: +        if i[j] == 1: +            for k in evidence_dit[j]: +                if i[k[0] - 1] != k[1]: -    if not flag: -        ans = max(ans, sum(h)) +    if flag == False: +        ans = max(ans, sum(i))