n=int(eval(input()))

a=[]

b=[]



for i in range(n):

      aa=int(eval(input()))

      a.append(aa)

      d=[]

      for j in range(aa):

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

            d.append((x,y))

      b.append(d)

cc=0

for i in range(2**n):

      L=[0]*n

      for j in range(n):

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

                  L[j]=1

      if 1 in L:

            flag=True

            for k in range(n):

                  if L[k]==1:

                        for m in range(a[k]):

                              if L[b[k][m][0]-1]!=b[k][m][1]:

                                    flag=False

                                    break

            if flag:

                  cc=max(sum(L),cc)

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

A=[]

B=[]

for i in range(n):

   a=int(eval(input()))

   A.append(a)

   d=[]

   for j in range(a):

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

      d.append((x,y))

   B.append(d)

ans=0

for i in range(2**n):

   L=[0]*n

   for j in range(n):

      if i>>j&1:

         L[j]=1

   if 1 in L:

      flag=True

      for k in range(n):

         if L[k]==1:

            for m in range(A[k]):

               if L[B[k][m][0]-1]!=B[k][m][1]:

                  flag=False

                  break

      if flag:

         ans=max(sum(L),ans)

print(ans)
n = int(eval(input()))
a = []
b = []
for i in range(n):
    aa = int(eval(input()))
    a.append(aa)
    d = []
    for j in range(aa):
        x, y = list(map(int, input().split()))
        d.append((x, y))
    b.append(d)
cc = 0
for i in range(2**n):
    L = [0] * n
    for j in range(n):
        if (i >> j) & 1:
            L[j] = 1
    if 1 in L:
        flag = True
        for k in range(n):
            if L[k] == 1:
                for m in range(a[k]):
                    if L[b[k][m][0] - 1] != b[k][m][1]:
                        flag = False
                        break
        if flag:
            cc = max(sum(L), cc)
print(cc)

n = int(eval(input()))
A = []
B = []
for i in range(n):
    a = int(eval(input()))
    A.append(a)
    d = []
    for j in range(a):
        x, y = list(map(int, input().split()))
        d.append((x, y))
    B.append(d)
ans = 0
for i in range(2**n):
    L = [0] * n
    for j in range(n):
        if i >> j & 1:
            L[j] = 1
    if 1 in L:
        flag = True
        for k in range(n):
            if L[k] == 1:
                for m in range(A[k]):
                    if L[B[k][m][0] - 1] != B[k][m][1]:
                        flag = False
                        break
        if flag:
            ans = max(sum(L), ans)
print(ans)

-a = [] -b = [] +A = [] +B = [] -    aa = int(eval(input())) -    a.append(aa) +    a = int(eval(input())) +    A.append(a) -    for j in range(aa): +    for j in range(a): -    b.append(d) -cc = 0 +    B.append(d) +ans = 0 -        if (i >> j) & 1: +        if i >> j & 1: -                for m in range(a[k]): -                    if L[b[k][m][0] - 1] != b[k][m][1]: +                for m in range(A[k]): +                    if L[B[k][m][0] - 1] != B[k][m][1]: -            cc = max(sum(L), cc) -print(cc) +            ans = max(sum(L), ans) +print(ans)