import sys

input = sys.stdin.readline

n = int(eval(input()))

chk = [[set(),set()] for _ in range(n)]

for o in range(n):

  a = int(eval(input()))

  for i in range(a):

    x,y = [int(i) for i in input().split()]

    if y == 0:

      chk[o][0].add(x-1)

    if y == 1:

      chk[o][1].add(x-1)

    

chk = tuple(chk)

answer = 0

for i in range(2**n):

  b = format(i,'b')

  b = b.zfill(n)[::-1]

  chk_0 = set()

  chk_1 = set()

  p = []

  for j in range(n):

    if b[j] == '1':

      p.append(j)

      chk_1.add(j)

    if b[j] == '0':

      chk_0.add(j)

  for i in p:

    if not chk[i][0] <= chk_0:

      break

    if not chk[i][1] <= chk_1:

      break

    if i == p[len(p)-1]:

      answer = max(answer,len(p))

      

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

a = []

xy = []

for i in range(n):

    a += [int(eval(input()))]

    xy += [[list(map(int,input().split())) for i in range(a[i])]]

honest = []

for i in range(2 ** n):

    flag = 0

    for j in range(n):

        if (i >> j)&1 == 1: #j番目は正直であるとき

            for person_state in xy[j]:

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

                  flag = 1 #矛盾が生じるとflagを立てる

                  break

    if flag == 0:

        honest += [bin(i)[2:].count("1")]

print((max(honest)))
import sys

input = sys.stdin.readline
n = int(eval(input()))
chk = [[set(), set()] for _ in range(n)]
for o in range(n):
    a = int(eval(input()))
    for i in range(a):
        x, y = [int(i) for i in input().split()]
        if y == 0:
            chk[o][0].add(x - 1)
        if y == 1:
            chk[o][1].add(x - 1)
chk = tuple(chk)
answer = 0
for i in range(2**n):
    b = format(i, "b")
    b = b.zfill(n)[::-1]
    chk_0 = set()
    chk_1 = set()
    p = []
    for j in range(n):
        if b[j] == "1":
            p.append(j)
            chk_1.add(j)
        if b[j] == "0":
            chk_0.add(j)
    for i in p:
        if not chk[i][0] <= chk_0:
            break
        if not chk[i][1] <= chk_1:
            break
        if i == p[len(p) - 1]:
            answer = max(answer, len(p))
print(answer)

n = int(eval(input()))
a = []
xy = []
for i in range(n):
    a += [int(eval(input()))]
    xy += [[list(map(int, input().split())) for i in range(a[i])]]
honest = []
for i in range(2**n):
    flag = 0
    for j in range(n):
        if (i >> j) & 1 == 1:  # j番目は正直であるとき
            for person_state in xy[j]:
                if (i >> (person_state[0] - 1) & 1) != person_state[1]:
                    flag = 1  # 矛盾が生じるとflagを立てる
                    break
    if flag == 0:
        honest += [bin(i)[2:].count("1")]
print((max(honest)))

-import sys - -input = sys.stdin.readline -chk = [[set(), set()] for _ in range(n)] -for o in range(n): -    a = int(eval(input())) -    for i in range(a): -        x, y = [int(i) for i in input().split()] -        if y == 0: -            chk[o][0].add(x - 1) -        if y == 1: -            chk[o][1].add(x - 1) -chk = tuple(chk) -answer = 0 +a = [] +xy = [] +for i in range(n): +    a += [int(eval(input()))] +    xy += [[list(map(int, input().split())) for i in range(a[i])]] +honest = [] -    b = format(i, "b") -    b = b.zfill(n)[::-1] -    chk_0 = set() -    chk_1 = set() -    p = [] +    flag = 0 -        if b[j] == "1": -            p.append(j) -            chk_1.add(j) -        if b[j] == "0": -            chk_0.add(j) -    for i in p: -        if not chk[i][0] <= chk_0: -            break -        if not chk[i][1] <= chk_1: -            break -        if i == p[len(p) - 1]: -            answer = max(answer, len(p)) -print(answer) +        if (i >> j) & 1 == 1:  # j番目は正直であるとき +            for person_state in xy[j]: +                if (i >> (person_state[0] - 1) & 1) != person_state[1]: +                    flag = 1  # 矛盾が生じるとflagを立てる +                    break +    if flag == 0: +        honest += [bin(i)[2:].count("1")] +print((max(honest)))