import re

n=int(eval(input()))

A=[]

for i in range(n):

    B=["."]*n

    for x,y in [list(map(int,input().split())) for k in range(int(eval(input())))]:

        B[x-1]=str(y)

    A.append("".join(B))



ans=0

for i in range(2**n):

    num=format(i,"b").zfill(n)

    cnt,flag=0,1

    for k,j in enumerate(num):

        result=re.search(r"".join(A[k]),num)

        if result!=None and j=="1":

            cnt +=1

        elif (result!=None and j=="0") or (result==None and j=="1"):

            flag=0

            break

    if flag:ans=max(ans,cnt)

print(ans)
import re

n=int(eval(input()))

A=[]

for i in range(n):

    word=["."]*n

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

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

        word[x-1]=str(y)

    A.append(word)



ans=0

for i in range(2**n):

    num=format(i, "b").zfill(n)

    flag,cnt=1,0

    for j,k in enumerate(num):

        search=re.search(r"".join(A[j]),num)

        if search!=None and k=="1":

            cnt +=1

        elif (search==None and k=="1") or (search!=None and k=="0"):

            flag=0

            break

    if flag:ans=max(ans,cnt)

print(ans)
import re

n = int(eval(input()))
A = []
for i in range(n):
    B = ["."] * n
    for x, y in [list(map(int, input().split())) for k in range(int(eval(input())))]:
        B[x - 1] = str(y)
    A.append("".join(B))
ans = 0
for i in range(2**n):
    num = format(i, "b").zfill(n)
    cnt, flag = 0, 1
    for k, j in enumerate(num):
        result = re.search(r"".join(A[k]), num)
        if result != None and j == "1":
            cnt += 1
        elif (result != None and j == "0") or (result == None and j == "1"):
            flag = 0
            break
    if flag:
        ans = max(ans, cnt)
print(ans)

import re

n = int(eval(input()))
A = []
for i in range(n):
    word = ["."] * n
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        word[x - 1] = str(y)
    A.append(word)
ans = 0
for i in range(2**n):
    num = format(i, "b").zfill(n)
    flag, cnt = 1, 0
    for j, k in enumerate(num):
        search = re.search(r"".join(A[j]), num)
        if search != None and k == "1":
            cnt += 1
        elif (search == None and k == "1") or (search != None and k == "0"):
            flag = 0
            break
    if flag:
        ans = max(ans, cnt)
print(ans)

-    B = ["."] * n -    for x, y in [list(map(int, input().split())) for k in range(int(eval(input())))]: -        B[x - 1] = str(y) -    A.append("".join(B)) +    word = ["."] * n +    for j in range(int(eval(input()))): +        x, y = list(map(int, input().split())) +        word[x - 1] = str(y) +    A.append(word) -    cnt, flag = 0, 1 -    for k, j in enumerate(num): -        result = re.search(r"".join(A[k]), num) -        if result != None and j == "1": +    flag, cnt = 1, 0 +    for j, k in enumerate(num): +        search = re.search(r"".join(A[j]), num) +        if search != None and k == "1": -        elif (result != None and j == "0") or (result == None and j == "1"): +        elif (search == None and k == "1") or (search != None and k == "0"):