n = int(eval(input()))

 

testimony = [[] for _ in range(n)]

for i in range(n):

    tmp = int(eval(input()))

    for j in range(tmp):

        person, state = list(map(int, input().split()))

        testimony[i].append([person-1, state])

#print(testimony)



from itertools import product

s = [0,1]

ptns = list(product(s, repeat=n))

ptns = list(reversed(ptns))

#print(ptns)



for i in range(len(ptns)):

    error = 0

    for j in range(n):

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

            for k in testimony[j]:

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

                    error = 1



    if error == 0:

        print((sum(ptns[i])))

        exit()

n = int(eval(input()))

 

testimony = [[] for _ in range(n)]

for i in range(n):

    tmp = int(eval(input()))

    for j in range(tmp):

        person, state = list(map(int, input().split()))

        testimony[i].append([person-1, state])

#print(testimony)



from itertools import product

s = [0,1]

ptns = sorted(list(product(s, repeat=n)), reverse=1)

#print(ptns)



for i in range(len(ptns)):

    for j in range(n):

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

            for k in testimony[j]:

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

                    break

            else:

                continue

            break

    else:

        print((sum(ptns[i])))

        exit()
n = int(eval(input()))
testimony = [[] for _ in range(n)]
for i in range(n):
    tmp = int(eval(input()))
    for j in range(tmp):
        person, state = list(map(int, input().split()))
        testimony[i].append([person - 1, state])
# print(testimony)
from itertools import product

s = [0, 1]
ptns = list(product(s, repeat=n))
ptns = list(reversed(ptns))
# print(ptns)
for i in range(len(ptns)):
    error = 0
    for j in range(n):
        if ptns[i][j] == 1:
            for k in testimony[j]:
                if ptns[i][k[0]] != k[1]:
                    error = 1
    if error == 0:
        print((sum(ptns[i])))
        exit()

n = int(eval(input()))
testimony = [[] for _ in range(n)]
for i in range(n):
    tmp = int(eval(input()))
    for j in range(tmp):
        person, state = list(map(int, input().split()))
        testimony[i].append([person - 1, state])
# print(testimony)
from itertools import product

s = [0, 1]
ptns = sorted(list(product(s, repeat=n)), reverse=1)
# print(ptns)
for i in range(len(ptns)):
    for j in range(n):
        if ptns[i][j] == 1:
            for k in testimony[j]:
                if ptns[i][k[0]] != k[1]:
                    break
            else:
                continue
            break
    else:
        print((sum(ptns[i])))
        exit()

-ptns = list(product(s, repeat=n)) -ptns = list(reversed(ptns)) +ptns = sorted(list(product(s, repeat=n)), reverse=1) -    error = 0 -                    error = 1 -    if error == 0: +                    break +            else: +                continue +            break +    else: