#ABC147 C

si = lambda: eval(input())

ni = lambda: int(eval(input()))

nm = lambda: list(map(int, input().split()))

nl = lambda: list(map(int, input().split()))

n=int(eval(input()))

shogen=[]

for _ in range(n):

    a=int(eval(input()))

    t=[]

    for __ in range(a):

        s=list(map(int,input().split()))

        t.append(s)

    shogen.append(t)



ans=0



for i in range(2**n):

    flag=True

    for j in range(n):

        if not flag:

            break

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

            for s in shogen[j]:

                if ((i>>s[0]-1)&1) !=s[1]:

                    flag=False

    if flag:

        mnt = bin(i).count("1")

        ans=max(ans,mnt)

print(ans)



n=int(eval(input()))

xy=[[] for i in range(n)]

for i in range(n):

  a=int(eval(input()))

  for j in range(a):

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

    xy[i].append([x,y])

ans=0

for b in range(1<<n):

  cnt=bin(b).count("1")

  if cnt<=ans:continue

  for j in range(n):

    if b&(1<<j):

      for x,y in xy[j]:

        if y==1 and b&(1<<x-1): continue

        if y==0 and b&(1<<x-1)==0: continue

        break

      else:

        continue

      break

  else:

    ans=cnt

print(ans)



# ABC147 C
si = lambda: eval(input())
ni = lambda: int(eval(input()))
nm = lambda: list(map(int, input().split()))
nl = lambda: list(map(int, input().split()))
n = int(eval(input()))
shogen = []
for _ in range(n):
    a = int(eval(input()))
    t = []
    for __ in range(a):
        s = list(map(int, input().split()))
        t.append(s)
    shogen.append(t)
ans = 0
for i in range(2**n):
    flag = True
    for j in range(n):
        if not flag:
            break
        if (i >> j) & 1:
            for s in shogen[j]:
                if ((i >> s[0] - 1) & 1) != s[1]:
                    flag = False
    if flag:
        mnt = bin(i).count("1")
        ans = max(ans, mnt)
print(ans)

n = int(eval(input()))
xy = [[] for i in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        xy[i].append([x, y])
ans = 0
for b in range(1 << n):
    cnt = bin(b).count("1")
    if cnt <= ans:
        continue
    for j in range(n):
        if b & (1 << j):
            for x, y in xy[j]:
                if y == 1 and b & (1 << x - 1):
                    continue
                if y == 0 and b & (1 << x - 1) == 0:
                    continue
                break
            else:
                continue
            break
    else:
        ans = cnt
print(ans)

-# ABC147 C -si = lambda: eval(input()) -ni = lambda: int(eval(input())) -nm = lambda: list(map(int, input().split())) -nl = lambda: list(map(int, input().split())) -shogen = [] -for _ in range(n): +xy = [[] for i in range(n)] +for i in range(n): -    t = [] -    for __ in range(a): -        s = list(map(int, input().split())) -        t.append(s) -    shogen.append(t) +    for j in range(a): +        x, y = list(map(int, input().split())) +        xy[i].append([x, y]) -for i in range(2**n): -    flag = True +for b in range(1 << n): +    cnt = bin(b).count("1") +    if cnt <= ans: +        continue -        if not flag: +        if b & (1 << j): +            for x, y in xy[j]: +                if y == 1 and b & (1 << x - 1): +                    continue +                if y == 0 and b & (1 << x - 1) == 0: +                    continue +                break +            else: +                continue -        if (i >> j) & 1: -            for s in shogen[j]: -                if ((i >> s[0] - 1) & 1) != s[1]: -                    flag = False -    if flag: -        mnt = bin(i).count("1") -        ans = max(ans, mnt) +    else: +        ans = cnt