n = int(eval(input()))

XY = []

ans = 0



for i in range(n):

    z = []

    

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

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

        z.append([x,y])

        

    XY.append(z)

        

for i in range(2**n):

    honest = 0

    mujunn = 0

    

    for j in range(n):

        if (i>>j) & 1:

            honest += 1

            

            for k in XY[j]:

                x = k[0] - 1

                y = k[1]

                

                if (i>>x)&1 != y:

                    mujunn = 1

                

    if mujunn == 0:

        ans = max(ans,honest)

        

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

XY = []

ans = 0



for i in range(n):

    z = []

    

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

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

        z.append([x,y])

        

    XY.append(z)

        

for i in range(2**n):

    honest = 0

    mujunn = 0

    

    for j in range(n):

        if (i>>j) & 1:

            honest += 1

            

            for k in XY[j]:

                x = k[0] - 1

                y = k[1]

                

                if (i>>x)&1 != y:

                    mujunn = 1

                    break

                    

        if mujunn == 1:

            break

                

    if mujunn == 0:

        ans = max(ans,honest)

        

print(ans)
n = int(eval(input()))
XY = []
ans = 0
for i in range(n):
    z = []
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        z.append([x, y])
    XY.append(z)
for i in range(2**n):
    honest = 0
    mujunn = 0
    for j in range(n):
        if (i >> j) & 1:
            honest += 1
            for k in XY[j]:
                x = k[0] - 1
                y = k[1]
                if (i >> x) & 1 != y:
                    mujunn = 1
    if mujunn == 0:
        ans = max(ans, honest)
print(ans)

n = int(eval(input()))
XY = []
ans = 0
for i in range(n):
    z = []
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        z.append([x, y])
    XY.append(z)
for i in range(2**n):
    honest = 0
    mujunn = 0
    for j in range(n):
        if (i >> j) & 1:
            honest += 1
            for k in XY[j]:
                x = k[0] - 1
                y = k[1]
                if (i >> x) & 1 != y:
                    mujunn = 1
                    break
        if mujunn == 1:
            break
    if mujunn == 0:
        ans = max(ans, honest)
print(ans)

+                    break +        if mujunn == 1: +            break