N=int(eval(input()))



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

for i in range(N):

  a=int(eval(input()))

  for j in range(a):

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

    A[i][x-1]=y

#正直者が正直者に不親切と言われていない

#→正直ものが不親切を正直者と言っていないか

ans=0

for i in range(2**N):

  ok=True

  for j in range(N):

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

      for k in range(N):

        if A[j][k]!=-1 and (i>>k&1)!=A[j][k]:

          ok=False

  if ok:

    ans=max(ans, bin(i).count("1"))

  

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



#正直者も発言に矛盾が生じない

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

for i in range(N):

    A=int(eval(input()))

    for a in range(A):

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

        L[i][x-1]=y

ans=0

for b in range(2**N):

    ok=True

    for i in range(N):

        if b>>i&1==1:

            l=L[i]

            for j,x in enumerate(l):

                if x!=-1 and b>>j&1!=x:

                    ok=False

    if ok:

        ans=max(ans, bin(b).count("1"))



print(ans)

N = int(eval(input()))
A = [[-1] * N for _ in range(N)]
for i in range(N):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        A[i][x - 1] = y
# 正直者が正直者に不親切と言われていない
# →正直ものが不親切を正直者と言っていないか
ans = 0
for i in range(2**N):
    ok = True
    for j in range(N):
        if (i >> j & 1) == 1:
            for k in range(N):
                if A[j][k] != -1 and (i >> k & 1) != A[j][k]:
                    ok = False
    if ok:
        ans = max(ans, bin(i).count("1"))
print(ans)

N = int(eval(input()))
# 正直者も発言に矛盾が生じない
L = [[-1] * N for _ in range(N)]
for i in range(N):
    A = int(eval(input()))
    for a in range(A):
        x, y = list(map(int, input().split()))
        L[i][x - 1] = y
ans = 0
for b in range(2**N):
    ok = True
    for i in range(N):
        if b >> i & 1 == 1:
            l = L[i]
            for j, x in enumerate(l):
                if x != -1 and b >> j & 1 != x:
                    ok = False
    if ok:
        ans = max(ans, bin(b).count("1"))
print(ans)

-A = [[-1] * N for _ in range(N)] +# 正直者も発言に矛盾が生じない +L = [[-1] * N for _ in range(N)] -    a = int(eval(input())) -    for j in range(a): +    A = int(eval(input())) +    for a in range(A): -        A[i][x - 1] = y -# 正直者が正直者に不親切と言われていない -# →正直ものが不親切を正直者と言っていないか +        L[i][x - 1] = y -for i in range(2**N): +for b in range(2**N): -    for j in range(N): -        if (i >> j & 1) == 1: -            for k in range(N): -                if A[j][k] != -1 and (i >> k & 1) != A[j][k]: +    for i in range(N): +        if b >> i & 1 == 1: +            l = L[i] +            for j, x in enumerate(l): +                if x != -1 and b >> j & 1 != x: -        ans = max(ans, bin(i).count("1")) +        ans = max(ans, bin(b).count("1"))