n = int(eval(input()))

a = [0] * n

s = [[]] * n



for i in range(n):

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

  tmp = [[]] * a[i]

  for j in range(a[i]):

    tmp[j] = [num for num in map(int, input().split())]

  s[i] = tmp

# print(n)

# print(a)

# print(s)

ans = 0

for i in range(2 ** n):

  pattern = '{:0' + str(n) + 'b}'

  bin_str = pattern.format(i)

  # print(bin_str)

  all_ok = True # すべての人の証言に矛盾がない

  total_honesty = 0

  for j in range(n):

    shogen = s[j]

    if bin_str[j] == '1':

      total_honesty += 1

      # 正直者とした場合

      for k in range(len(shogen)):

        x, y = shogen[k]

        x -= 1

        if int(bin_str[x]) != y:

          all_ok = False

          break

  if all_ok:

    if ans < total_honesty:

      ans = total_honesty

print(ans)

n = int(eval(input()))



a = [0] * n

sl = []



for i in range(n):

  a = int(eval(input()))

  s = []

  for j in range(a):

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

    s.append([x, y])

  sl.append(s)

ans = 0



# bit 全探索

# 1 = 正直者、0 = 不親切な人

for i in range(1 << n):

  #print('pattern', bin(i))

  all_ok = True

  for j in range(n):

    # 人j が正直者かどうか

    #print('j : {}'.format(j))

    if i & (1 << j):

      # print(j)

      # 正直者であれば証言に矛盾があってはいけない

      s = sl[j]

      for k in range(len(s)):

        target =  s[k][0]

        kind = s[k][1]

        # print('target {} : kind {}'.format(target, kind))

        #print(target, kind, i & (1 << (target-1)), bool(i & (1 << (target-1))), bool(kind))

        rk = 1 if (i & (1 << (target-1))) > 0 else 0

        if rk != kind :

          #print('証言NG')

          # 証言がNG

          all_ok = False

          break

    if not all_ok:

      break

  else:

    # すべての正直者に矛盾がないパターン

    #print('ok', bin(i))

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

    

#print(sl)

print(ans)
n = int(eval(input()))
a = [0] * n
s = [[]] * n
for i in range(n):
    a[i] = int(eval(input()))
    tmp = [[]] * a[i]
    for j in range(a[i]):
        tmp[j] = [num for num in map(int, input().split())]
    s[i] = tmp
# print(n)
# print(a)
# print(s)
ans = 0
for i in range(2**n):
    pattern = "{:0" + str(n) + "b}"
    bin_str = pattern.format(i)
    # print(bin_str)
    all_ok = True  # すべての人の証言に矛盾がない
    total_honesty = 0
    for j in range(n):
        shogen = s[j]
        if bin_str[j] == "1":
            total_honesty += 1
            # 正直者とした場合
            for k in range(len(shogen)):
                x, y = shogen[k]
                x -= 1
                if int(bin_str[x]) != y:
                    all_ok = False
                    break
    if all_ok:
        if ans < total_honesty:
            ans = total_honesty
print(ans)

n = int(eval(input()))
a = [0] * n
sl = []
for i in range(n):
    a = int(eval(input()))
    s = []
    for j in range(a):
        x, y = list(map(int, input().split()))
        s.append([x, y])
    sl.append(s)
ans = 0
# bit 全探索
# 1 = 正直者、0 = 不親切な人
for i in range(1 << n):
    # print('pattern', bin(i))
    all_ok = True
    for j in range(n):
        # 人j が正直者かどうか
        # print('j : {}'.format(j))
        if i & (1 << j):
            # print(j)
            # 正直者であれば証言に矛盾があってはいけない
            s = sl[j]
            for k in range(len(s)):
                target = s[k][0]
                kind = s[k][1]
                # print('target {} : kind {}'.format(target, kind))
                # print(target, kind, i & (1 << (target-1)), bool(i & (1 << (target-1))), bool(kind))
                rk = 1 if (i & (1 << (target - 1))) > 0 else 0
                if rk != kind:
                    # print('証言NG')
                    # 証言がNG
                    all_ok = False
                    break
        if not all_ok:
            break
    else:
        # すべての正直者に矛盾がないパターン
        # print('ok', bin(i))
        ans = max(ans, bin(i).count("1"))
# print(sl)
print(ans)

-s = [[]] * n +sl = [] -    a[i] = int(eval(input())) -    tmp = [[]] * a[i] -    for j in range(a[i]): -        tmp[j] = [num for num in map(int, input().split())] -    s[i] = tmp -# print(n) -# print(a) -# print(s) +    a = int(eval(input())) +    s = [] +    for j in range(a): +        x, y = list(map(int, input().split())) +        s.append([x, y]) +    sl.append(s) -for i in range(2**n): -    pattern = "{:0" + str(n) + "b}" -    bin_str = pattern.format(i) -    # print(bin_str) -    all_ok = True  # すべての人の証言に矛盾がない -    total_honesty = 0 +# bit 全探索 +# 1 = 正直者、0 = 不親切な人 +for i in range(1 << n): +    # print('pattern', bin(i)) +    all_ok = True -        shogen = s[j] -        if bin_str[j] == "1": -            total_honesty += 1 -            # 正直者とした場合 -            for k in range(len(shogen)): -                x, y = shogen[k] -                x -= 1 -                if int(bin_str[x]) != y: +        # 人j が正直者かどうか +        # print('j : {}'.format(j)) +        if i & (1 << j): +            # print(j) +            # 正直者であれば証言に矛盾があってはいけない +            s = sl[j] +            for k in range(len(s)): +                target = s[k][0] +                kind = s[k][1] +                # print('target {} : kind {}'.format(target, kind)) +                # print(target, kind, i & (1 << (target-1)), bool(i & (1 << (target-1))), bool(kind)) +                rk = 1 if (i & (1 << (target - 1))) > 0 else 0 +                if rk != kind: +                    # print('証言NG') +                    # 証言がNG -    if all_ok: -        if ans < total_honesty: -            ans = total_honesty +        if not all_ok: +            break +    else: +        # すべての正直者に矛盾がないパターン +        # print('ok', bin(i)) +        ans = max(ans, bin(i).count("1")) +# print(sl)