import sys

sys.setrecursionlimit(10**7)



N = int(eval(input()))



claim = []



for _ in range(N):

    memo = []

    A = int(eval(input()))

    for _ in range(A):

        x, y = input().split()

        memo.append((x,y))

    claim.append(memo)



maximam = 0

for i in range(2**N):

    flag = True

    bin_i = (N - len(str(bin(i))[2:]))*["0"] + list(bin(i))[2:]

    for j, man in enumerate(bin_i):

        if man == "0":

            continue

        for x, y in claim[j]:

            if bin_i[int(x)-1] != y:

                flag = False

    if flag:

        count = 0

        for b in bin_i:

            if b=="1":

                count+=1

        maximam = max(maximam,count)

print(count)
import sys

sys.setrecursionlimit(10**7)



N = int(eval(input()))



claim = []



for _ in range(N):

    memo = []

    A = int(eval(input()))

    for _ in range(A):

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

        memo.append((x,y))

    claim.append(memo)



maximam = 0

for bit in range(2**N):

    flag = True

    count = 0

    for i in range(N):

        if bit & (1<<i):

            count+=1

            for x, y in claim[i]:

                if (bit & (1<<(x-1)) and y==0) or (not (bit & (1<<(x-1))) and y==1):

                    flag = False

    if flag:

        maximam = max(maximam,count)

print(maximam)
import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
claim = []
for _ in range(N):
    memo = []
    A = int(eval(input()))
    for _ in range(A):
        x, y = input().split()
        memo.append((x, y))
    claim.append(memo)
maximam = 0
for i in range(2**N):
    flag = True
    bin_i = (N - len(str(bin(i))[2:])) * ["0"] + list(bin(i))[2:]
    for j, man in enumerate(bin_i):
        if man == "0":
            continue
        for x, y in claim[j]:
            if bin_i[int(x) - 1] != y:
                flag = False
    if flag:
        count = 0
        for b in bin_i:
            if b == "1":
                count += 1
        maximam = max(maximam, count)
print(count)

import sys

sys.setrecursionlimit(10**7)
N = int(eval(input()))
claim = []
for _ in range(N):
    memo = []
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        memo.append((x, y))
    claim.append(memo)
maximam = 0
for bit in range(2**N):
    flag = True
    count = 0
    for i in range(N):
        if bit & (1 << i):
            count += 1
            for x, y in claim[i]:
                if (bit & (1 << (x - 1)) and y == 0) or (
                    not (bit & (1 << (x - 1))) and y == 1
                ):
                    flag = False
    if flag:
        maximam = max(maximam, count)
print(maximam)

-        x, y = input().split() +        x, y = list(map(int, input().split())) -for i in range(2**N): +for bit in range(2**N): -    bin_i = (N - len(str(bin(i))[2:])) * ["0"] + list(bin(i))[2:] -    for j, man in enumerate(bin_i): -        if man == "0": -            continue -        for x, y in claim[j]: -            if bin_i[int(x) - 1] != y: -                flag = False +    count = 0 +    for i in range(N): +        if bit & (1 << i): +            count += 1 +            for x, y in claim[i]: +                if (bit & (1 << (x - 1)) and y == 0) or ( +                    not (bit & (1 << (x - 1))) and y == 1 +                ): +                    flag = False -        count = 0 -        for b in bin_i: -            if b == "1": -                count += 1 -print(count) +print(maximam)