N=int(eval(input()))

g=[[-1]*N for _ in range(N)]

ans=0

for i in range(N):

    A=int(eval(input()))

    for _ in range(A):

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

        g[i][x-1]=y

for s in range(2**N):

    flag=1

    for i in range(N):

        if (s>>i&1):

            for j in range(N):

                if g[i][j]!=-1 and (s>>j&1)!=g[i][j]:

                    flag=0

    if flag==1:

        t=0

        x=s

        while x>0:

            t+=x%2

            x//=2

        ans=max(ans,t)

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

g=[[-1]*N for _ in range(N)]

ans=0

for i in range(N):

    A=int(eval(input()))

    for _ in range(A):

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

        g[i][x-1]=y

for s in range(2**N):

    flag=1

    for i in range(N):

        if (s>>i&1):

            for j in range(N):

                if g[i][j]!=-1 and (s>>j&1)!=g[i][j]:

                    flag=0

                    break

        if flag==0:break

    if flag==1:

        t=0

        x=s

        while x>0:

            t+=x%2

            x//=2

        ans=max(ans,t)

print(ans)
N = int(eval(input()))
g = [[-1] * N for _ in range(N)]
ans = 0
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        g[i][x - 1] = y
for s in range(2**N):
    flag = 1
    for i in range(N):
        if s >> i & 1:
            for j in range(N):
                if g[i][j] != -1 and (s >> j & 1) != g[i][j]:
                    flag = 0
    if flag == 1:
        t = 0
        x = s
        while x > 0:
            t += x % 2
            x //= 2
        ans = max(ans, t)
print(ans)

N = int(eval(input()))
g = [[-1] * N for _ in range(N)]
ans = 0
for i in range(N):
    A = int(eval(input()))
    for _ in range(A):
        x, y = list(map(int, input().split()))
        g[i][x - 1] = y
for s in range(2**N):
    flag = 1
    for i in range(N):
        if s >> i & 1:
            for j in range(N):
                if g[i][j] != -1 and (s >> j & 1) != g[i][j]:
                    flag = 0
                    break
        if flag == 0:
            break
    if flag == 1:
        t = 0
        x = s
        while x > 0:
            t += x % 2
            x //= 2
        ans = max(ans, t)
print(ans)

+                    break +        if flag == 0: +            break