import itertools



N = int(eval(input()))



syougen_list = []

people = [-1] * N

for i in range(N):

    a_i = int(eval(input()))

    a_i_list = []

    for j in range(a_i):

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

    syougen_list.append(a_i_list)





output = 0

for i in itertools.product([1,0], repeat=N):

    legal = True

    for index, j in enumerate(i):

        if j == 1:

            syougen = syougen_list[index]

            for k in syougen:

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

                    legal = False

                    break

    if not legal:

        continue



    match = True

    honest_syougen_list = []

    for index, j in enumerate(i):

        if j == 1:

            honest_syougen_list += syougen_list[index]

    for j in honest_syougen_list:

        if people[j[0] - 1] == -1:

            people[j[0] - 1] = j[1]

        elif people[j[0] - 1] != j[1]:

            match = False

            break

    if match:

        number = i.count(1)

        if number >= output:

            output = number



print(output)
import itertools



N = int(eval(input()))



syougen_list = []

for i in range(N):

    a_i = int(eval(input()))

    a_i_list = []

    for j in range(a_i):

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

    syougen_list.append(a_i_list)





output = 0

for i in itertools.product([1,0], repeat=N):

    legal = True

    for index, j in enumerate(i):

        if j == 1:

            syougen = syougen_list[index]

            for k in syougen:

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

                    legal = False

                    break

            if not legal:

                break

    if legal:

        number = i.count(1)

        if number >= output:

            output = number



print(output)
import itertools

N = int(eval(input()))
syougen_list = []
people = [-1] * N
for i in range(N):
    a_i = int(eval(input()))
    a_i_list = []
    for j in range(a_i):
        a_i_list.append(list(map(int, input().split())))
    syougen_list.append(a_i_list)
output = 0
for i in itertools.product([1, 0], repeat=N):
    legal = True
    for index, j in enumerate(i):
        if j == 1:
            syougen = syougen_list[index]
            for k in syougen:
                if i[k[0] - 1] != k[1]:
                    legal = False
                    break
    if not legal:
        continue
    match = True
    honest_syougen_list = []
    for index, j in enumerate(i):
        if j == 1:
            honest_syougen_list += syougen_list[index]
    for j in honest_syougen_list:
        if people[j[0] - 1] == -1:
            people[j[0] - 1] = j[1]
        elif people[j[0] - 1] != j[1]:
            match = False
            break
    if match:
        number = i.count(1)
        if number >= output:
            output = number
print(output)

import itertools

N = int(eval(input()))
syougen_list = []
for i in range(N):
    a_i = int(eval(input()))
    a_i_list = []
    for j in range(a_i):
        a_i_list.append(list(map(int, input().split())))
    syougen_list.append(a_i_list)
output = 0
for i in itertools.product([1, 0], repeat=N):
    legal = True
    for index, j in enumerate(i):
        if j == 1:
            syougen = syougen_list[index]
            for k in syougen:
                if i[k[0] - 1] != k[1]:
                    legal = False
                    break
            if not legal:
                break
    if legal:
        number = i.count(1)
        if number >= output:
            output = number
print(output)

-people = [-1] * N -    if not legal: -        continue -    match = True -    honest_syougen_list = [] -    for index, j in enumerate(i): -        if j == 1: -            honest_syougen_list += syougen_list[index] -    for j in honest_syougen_list: -        if people[j[0] - 1] == -1: -            people[j[0] - 1] = j[1] -        elif people[j[0] - 1] != j[1]: -            match = False -            break -    if match: +            if not legal: +                break +    if legal: