from itertools import product

N=int(eval(input()))

data=[]

for i in range(N):

    for j in range(int(eval(input()))):

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

        data.append((i,x-1,y))

#print(data)



ans=0

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

    #print(i)

    s=True

    for k in data:

        if i[k[0]]==1 and i[k[1]]!=k[2]:

            s=False

            break

    if s:

        ans=max(ans,sum(i))

print(ans)

from itertools import product



N=int(eval(input()))

data=[]

for i in range(N):

    for j in range(int(eval(input()))):

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

        data.append((i,x-1,y)) #iさんがx-1さんに嘘(0)or正直(1)





ans=0

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

    ok=True

    for j in data:

        if i[j[0]]==1 and i[j[1]]!=j[2]:

            ok = False

            break

    if ok:

        ans=max(ans,sum(i))

print(ans)
from itertools import product

N = int(eval(input()))
data = []
for i in range(N):
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        data.append((i, x - 1, y))
# print(data)
ans = 0
for i in product([1, 0], repeat=N):
    # print(i)
    s = True
    for k in data:
        if i[k[0]] == 1 and i[k[1]] != k[2]:
            s = False
            break
    if s:
        ans = max(ans, sum(i))
print(ans)

from itertools import product

N = int(eval(input()))
data = []
for i in range(N):
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        data.append((i, x - 1, y))  # iさんがx-1さんに嘘(0)or正直(1)
ans = 0
for i in product([0, 1], repeat=N):
    ok = True
    for j in data:
        if i[j[0]] == 1 and i[j[1]] != j[2]:
            ok = False
            break
    if ok:
        ans = max(ans, sum(i))
print(ans)

-        data.append((i, x - 1, y)) -# print(data) +        data.append((i, x - 1, y))  # iさんがx-1さんに嘘(0)or正直(1) -for i in product([1, 0], repeat=N): -    # print(i) -    s = True -    for k in data: -        if i[k[0]] == 1 and i[k[1]] != k[2]: -            s = False +for i in product([0, 1], repeat=N): +    ok = True +    for j in data: +        if i[j[0]] == 1 and i[j[1]] != j[2]: +            ok = False -    if s: +    if ok: