N=int(eval(input()))

honest=[0 for i in range(N)]

liar=[0 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()))

    if y==0:

      liar[i]|=(1<<(x-1))

    else:

      honest[i]|=(1<<(x-1))



ans=0

for i in range(2**N):

  ok=True

  for j in range(N):

    if (i>>j)&1:

      hon=honest[j]

      pat=i

      while hon>0:

        if hon&1==1 and pat&1==0:

          ok=False

          break

        hon>>=1

        pat>>=1

      li=liar[j]

      pat=i

      while li>0:

        if li&1==1 and pat&1==1:

          ok=False

          break

        li>>=1

        pat>>=1

      if not ok:

        break

  if ok:

    val=i

    cnt=0

    while val>0:

      if val&1==1:

        cnt+=1

      val>>=1

    ans=max(ans,cnt)

        

print(ans)

import sys

readline = sys.stdin.readline



N = int(readline())

statement = [[] for i in range(N)]

for i in range(N):

  A = int(readline())

  for j in range(A):

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

    statement[i].append([x - 1,y])

  

# N人の誰が正直者か、全探索して、矛盾がないパターンはOK

ans = 0

for i in range(2 ** N):

  ok = True

  for j in range(N):

    if (i >> j) & 1:

      # 人jのコメントを検証

      for s in statement[j]:

        person = s[0]

        flag = s[1]

        if ((i >> person) & 1) != flag:

          # 間違ってる

          ok = False

          break

    if not ok:

      break

  if ok:

    honest = str(bin(i)).count("1")

    if ans < honest:

      ans = honest

print(ans)

N = int(eval(input()))
honest = [0 for i in range(N)]
liar = [0 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()))
        if y == 0:
            liar[i] |= 1 << (x - 1)
        else:
            honest[i] |= 1 << (x - 1)
ans = 0
for i in range(2**N):
    ok = True
    for j in range(N):
        if (i >> j) & 1:
            hon = honest[j]
            pat = i
            while hon > 0:
                if hon & 1 == 1 and pat & 1 == 0:
                    ok = False
                    break
                hon >>= 1
                pat >>= 1
            li = liar[j]
            pat = i
            while li > 0:
                if li & 1 == 1 and pat & 1 == 1:
                    ok = False
                    break
                li >>= 1
                pat >>= 1
            if not ok:
                break
    if ok:
        val = i
        cnt = 0
        while val > 0:
            if val & 1 == 1:
                cnt += 1
            val >>= 1
        ans = max(ans, cnt)
print(ans)

import sys

readline = sys.stdin.readline
N = int(readline())
statement = [[] for i in range(N)]
for i in range(N):
    A = int(readline())
    for j in range(A):
        x, y = list(map(int, readline().split()))
        statement[i].append([x - 1, y])
# N人の誰が正直者か、全探索して、矛盾がないパターンはOK
ans = 0
for i in range(2**N):
    ok = True
    for j in range(N):
        if (i >> j) & 1:
            # 人jのコメントを検証
            for s in statement[j]:
                person = s[0]
                flag = s[1]
                if ((i >> person) & 1) != flag:
                    # 間違ってる
                    ok = False
                    break
        if not ok:
            break
    if ok:
        honest = str(bin(i)).count("1")
        if ans < honest:
            ans = honest
print(ans)

-N = int(eval(input())) -honest = [0 for i in range(N)] -liar = [0 for i in range(N)] +import sys + +readline = sys.stdin.readline +N = int(readline()) +statement = [[] for i in range(N)] -    a = int(eval(input())) -    for j in range(a): -        x, y = list(map(int, input().split())) -        if y == 0: -            liar[i] |= 1 << (x - 1) -        else: -            honest[i] |= 1 << (x - 1) +    A = int(readline()) +    for j in range(A): +        x, y = list(map(int, readline().split())) +        statement[i].append([x - 1, y]) +# N人の誰が正直者か、全探索して、矛盾がないパターンはOK -            hon = honest[j] -            pat = i -            while hon > 0: -                if hon & 1 == 1 and pat & 1 == 0: +            # 人jのコメントを検証 +            for s in statement[j]: +                person = s[0] +                flag = s[1] +                if ((i >> person) & 1) != flag: +                    # 間違ってる -                hon >>= 1 -                pat >>= 1 -            li = liar[j] -            pat = i -            while li > 0: -                if li & 1 == 1 and pat & 1 == 1: -                    ok = False -                    break -                li >>= 1 -                pat >>= 1 -            if not ok: -                break +        if not ok: +            break -        val = i -        cnt = 0 -        while val > 0: -            if val & 1 == 1: -                cnt += 1 -            val >>= 1 -        ans = max(ans, cnt) +        honest = str(bin(i)).count("1") +        if ans < honest: +            ans = honest