n=int(eval(input()))

a=[]

for i in range(n):

    x=int(eval(input()))

    aa=[[int(i) for i in input().split()] for i in range(x)]

    a.append(aa)

#print(a)



ans=0

for i in range(2**n):

    status=[True]*n

    for j in range(n):

        if ((i>>j)&1):

            status[j]=False

    check=[None]*n

    flag=True

    for i in range(n):

        if status[i]==True:

            for x,y in a[i]:

                if y==1 and status[x-1]==True and (check[x-1]==None or check[x-1]==True):

                    check[x-1]=True

                elif y==1 and (check[x-1]==False or status[x-1]==False):

                    flag=False

                elif y==0 and status[x-1]==False and (check[x-1]==None or check[x-1]==False):

                    check[x-1]=False

                elif y==0 and (check[x-1]==True or status[x-1]==True):

                    flag=False

    if flag:

        #print(status,check)

        cnt=status.count(True)

        ans=max(ans,cnt)

print(ans)
n=int(eval(input()))

a=[]

for i in range(n):

    x=int(eval(input()))

    b=[[int(i) for i in input().split()] for i in range(x)]

    a.append(b)



ans=0



for i in range(2**n):

    status=[True]*n

    for j in range(n):

        if ((i>>j)&1):

            status[j]=False

    

    judge=[None]*n

    contradiction=False

    

    for x,person in enumerate(a):

        if status[x]==False:

            continue

        for testimony in person:

            if testimony[1]==1: 

                if judge[testimony[0]-1]!=False and status[testimony[0]-1]==True:

                    judge[testimony[0]-1]=True

                else:

                    contradiction=True

            else:

                if judge[testimony[0]-1]!=True and status[testimony[0]-1]==False:

                    judge[testimony[0]-1]=False

                else:

                    contradiction=True



    if contradiction==False:

        ans=max(ans,status.count(True))

print(ans)

            
n = int(eval(input()))
a = []
for i in range(n):
    x = int(eval(input()))
    aa = [[int(i) for i in input().split()] for i in range(x)]
    a.append(aa)
# print(a)
ans = 0
for i in range(2**n):
    status = [True] * n
    for j in range(n):
        if (i >> j) & 1:
            status[j] = False
    check = [None] * n
    flag = True
    for i in range(n):
        if status[i] == True:
            for x, y in a[i]:
                if (
                    y == 1
                    and status[x - 1] == True
                    and (check[x - 1] == None or check[x - 1] == True)
                ):
                    check[x - 1] = True
                elif y == 1 and (check[x - 1] == False or status[x - 1] == False):
                    flag = False
                elif (
                    y == 0
                    and status[x - 1] == False
                    and (check[x - 1] == None or check[x - 1] == False)
                ):
                    check[x - 1] = False
                elif y == 0 and (check[x - 1] == True or status[x - 1] == True):
                    flag = False
    if flag:
        # print(status,check)
        cnt = status.count(True)
        ans = max(ans, cnt)
print(ans)

n = int(eval(input()))
a = []
for i in range(n):
    x = int(eval(input()))
    b = [[int(i) for i in input().split()] for i in range(x)]
    a.append(b)
ans = 0
for i in range(2**n):
    status = [True] * n
    for j in range(n):
        if (i >> j) & 1:
            status[j] = False
    judge = [None] * n
    contradiction = False
    for x, person in enumerate(a):
        if status[x] == False:
            continue
        for testimony in person:
            if testimony[1] == 1:
                if (
                    judge[testimony[0] - 1] != False
                    and status[testimony[0] - 1] == True
                ):
                    judge[testimony[0] - 1] = True
                else:
                    contradiction = True
            else:
                if (
                    judge[testimony[0] - 1] != True
                    and status[testimony[0] - 1] == False
                ):
                    judge[testimony[0] - 1] = False
                else:
                    contradiction = True
    if contradiction == False:
        ans = max(ans, status.count(True))
print(ans)

-    aa = [[int(i) for i in input().split()] for i in range(x)] -    a.append(aa) -# print(a) +    b = [[int(i) for i in input().split()] for i in range(x)] +    a.append(b) -    check = [None] * n -    flag = True -    for i in range(n): -        if status[i] == True: -            for x, y in a[i]: +    judge = [None] * n +    contradiction = False +    for x, person in enumerate(a): +        if status[x] == False: +            continue +        for testimony in person: +            if testimony[1] == 1: -                    y == 1 -                    and status[x - 1] == True -                    and (check[x - 1] == None or check[x - 1] == True) +                    judge[testimony[0] - 1] != False +                    and status[testimony[0] - 1] == True -                    check[x - 1] = True -                elif y == 1 and (check[x - 1] == False or status[x - 1] == False): -                    flag = False -                elif ( -                    y == 0 -                    and status[x - 1] == False -                    and (check[x - 1] == None or check[x - 1] == False) +                    judge[testimony[0] - 1] = True +                else: +                    contradiction = True +            else: +                if ( +                    judge[testimony[0] - 1] != True +                    and status[testimony[0] - 1] == False -                    check[x - 1] = False -                elif y == 0 and (check[x - 1] == True or status[x - 1] == True): -                    flag = False -    if flag: -        # print(status,check) -        cnt = status.count(True) -        ans = max(ans, cnt) +                    judge[testimony[0] - 1] = False +                else: +                    contradiction = True +    if contradiction == False: +        ans = max(ans, status.count(True))