n = int(eval(input()))

lst = [[-1 for _ in range(n)] for __ in range(n)]

for i in range(n):

    ai = int(eval(input()))

    for j in range(ai):

        hito, which = list(map(int, input().split()))

        lst[i][hito-1] = which



ans = 0

muri = 0

for i in range(2**n):

    kumi = list(format(i, '0'+str(n)+'b'))

    temp = 0

    muri = 0

    for j in range(n):

        if muri == 1:

            break

        elif kumi[j] == '1':

            for k in range(n):

                if (lst[k][j] == 0 and kumi[k] == '1') or (lst[j][k] == 1 and kumi[k] == '0'):

                    muri = 1

                    break

            if muri == 0:

                temp += 1

    if muri == 0:

        ans = max(ans, temp)



print(ans)
import itertools



n = int(eval(input()))

lst = []

for i in range(n):

    ai = int(eval(input()))

    lsti = []

    for j in range(ai):

        xj, yj = list(map(int, input().split()))

        xj -= 1

        lsti.append([xj, yj])

    lst.append(lsti)



ans = 0

for v in itertools.product([0, 1], repeat=n):

    ok = 1

    for i in range(n):

        if v[i] == 0: continue

        if ok == 0: break

        lsti = lst[i]

        for xj, yj in lsti:

            if v[xj] != yj:

                ok = 0

                break

    if ok == 1:

        ans = max(ans, sum(v))



print(ans)
n = int(eval(input()))
lst = [[-1 for _ in range(n)] for __ in range(n)]
for i in range(n):
    ai = int(eval(input()))
    for j in range(ai):
        hito, which = list(map(int, input().split()))
        lst[i][hito - 1] = which
ans = 0
muri = 0
for i in range(2**n):
    kumi = list(format(i, "0" + str(n) + "b"))
    temp = 0
    muri = 0
    for j in range(n):
        if muri == 1:
            break
        elif kumi[j] == "1":
            for k in range(n):
                if (lst[k][j] == 0 and kumi[k] == "1") or (
                    lst[j][k] == 1 and kumi[k] == "0"
                ):
                    muri = 1
                    break
            if muri == 0:
                temp += 1
    if muri == 0:
        ans = max(ans, temp)
print(ans)

import itertools

n = int(eval(input()))
lst = []
for i in range(n):
    ai = int(eval(input()))
    lsti = []
    for j in range(ai):
        xj, yj = list(map(int, input().split()))
        xj -= 1
        lsti.append([xj, yj])
    lst.append(lsti)
ans = 0
for v in itertools.product([0, 1], repeat=n):
    ok = 1
    for i in range(n):
        if v[i] == 0:
            continue
        if ok == 0:
            break
        lsti = lst[i]
        for xj, yj in lsti:
            if v[xj] != yj:
                ok = 0
                break
    if ok == 1:
        ans = max(ans, sum(v))
print(ans)

+import itertools + -lst = [[-1 for _ in range(n)] for __ in range(n)] +lst = [] +    lsti = [] -        hito, which = list(map(int, input().split())) -        lst[i][hito - 1] = which +        xj, yj = list(map(int, input().split())) +        xj -= 1 +        lsti.append([xj, yj]) +    lst.append(lsti) -muri = 0 -for i in range(2**n): -    kumi = list(format(i, "0" + str(n) + "b")) -    temp = 0 -    muri = 0 -    for j in range(n): -        if muri == 1: +for v in itertools.product([0, 1], repeat=n): +    ok = 1 +    for i in range(n): +        if v[i] == 0: +            continue +        if ok == 0: -        elif kumi[j] == "1": -            for k in range(n): -                if (lst[k][j] == 0 and kumi[k] == "1") or ( -                    lst[j][k] == 1 and kumi[k] == "0" -                ): -                    muri = 1 -                    break -            if muri == 0: -                temp += 1 -    if muri == 0: -        ans = max(ans, temp) +        lsti = lst[i] +        for xj, yj in lsti: +            if v[xj] != yj: +                ok = 0 +                break +    if ok == 1: +        ans = max(ans, sum(v))