n = int(eval(input()))

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

for i in range(n):

  a = int(eval(input()))

  for j in range(a):

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

    x -= 1

    xy[i] += [[x, y]]

result = 0

for i in range(2**n):

  dic = {i:-1 for i in range(n)}

  flag = True 

  ans = 0

  for j in range(n):

    if (i>>j)&1:

      if dic[j] != -1 and dic[j] != 1:

        flag = False

        break

      dic[j] = 1

      for x, y in xy[j]:

        if dic[x] == -1:

          dic[x] = y 

        elif dic[x] != -1 and dic[x] != y:

          flag = False

          break

      if flag:

        ans += 1

    else:

      if dic[j] != -1 and dic[j] == 1:

        flag = False

        break

      dic[j] = 0

      """

      for x, y in xy[j]:

        if dic[x] == -1:

          dic[x] = 1-y 

        elif dic[x] != -1 and dic[x] == y:

          flag = False

          break

      """



  if flag:

    result = max(result, ans)



print(result)
N = int(eval(input()))

A = []

xy = []



for _ in range(N):

  a = int(eval(input()))

  tmp = [list(map(int, input().split())) for _ in range(a)]

  xy += [tmp]



ans = 0

for i in range(2**N):

  d = {i:-1 for i in range(1, N+1)}

  flag = True

  tmp = 0

  #print("---i---", i)

  for j in range(N):

    #print(d, j)

    if (i>>j)&1: # 正直

      tmp += 1

      if d[j+1] == 0:

        flag = False

        break

      d[j+1] = 1

      for x, y in xy[j]:

        if d[x] == -1:

          d[x] = y

        else:

          if d[x] != y:

            flag = False

            break

    else:

      if d[j+1] == 1:

        flag = False

        break

      d[j+1] = 0

    

  if flag:

    ans = max(tmp, ans)



print(ans)

n = int(eval(input()))
xy = [[] for _ in range(n)]
for i in range(n):
    a = int(eval(input()))
    for j in range(a):
        x, y = list(map(int, input().split()))
        x -= 1
        xy[i] += [[x, y]]
result = 0
for i in range(2**n):
    dic = {i: -1 for i in range(n)}
    flag = True
    ans = 0
    for j in range(n):
        if (i >> j) & 1:
            if dic[j] != -1 and dic[j] != 1:
                flag = False
                break
            dic[j] = 1
            for x, y in xy[j]:
                if dic[x] == -1:
                    dic[x] = y
                elif dic[x] != -1 and dic[x] != y:
                    flag = False
                    break
            if flag:
                ans += 1
        else:
            if dic[j] != -1 and dic[j] == 1:
                flag = False
                break
            dic[j] = 0
            """
      for x, y in xy[j]:
        if dic[x] == -1:
          dic[x] = 1-y 
        elif dic[x] != -1 and dic[x] == y:
          flag = False
          break
      """
    if flag:
        result = max(result, ans)
print(result)

N = int(eval(input()))
A = []
xy = []
for _ in range(N):
    a = int(eval(input()))
    tmp = [list(map(int, input().split())) for _ in range(a)]
    xy += [tmp]
ans = 0
for i in range(2**N):
    d = {i: -1 for i in range(1, N + 1)}
    flag = True
    tmp = 0
    # print("---i---", i)
    for j in range(N):
        # print(d, j)
        if (i >> j) & 1:  # 正直
            tmp += 1
            if d[j + 1] == 0:
                flag = False
                break
            d[j + 1] = 1
            for x, y in xy[j]:
                if d[x] == -1:
                    d[x] = y
                else:
                    if d[x] != y:
                        flag = False
                        break
        else:
            if d[j + 1] == 1:
                flag = False
                break
            d[j + 1] = 0
    if flag:
        ans = max(tmp, ans)
print(ans)

-n = int(eval(input())) -xy = [[] for _ in range(n)] -for i in range(n): +N = int(eval(input())) +A = [] +xy = [] +for _ in range(N): -    for j in range(a): -        x, y = list(map(int, input().split())) -        x -= 1 -        xy[i] += [[x, y]] -result = 0 -for i in range(2**n): -    dic = {i: -1 for i in range(n)} +    tmp = [list(map(int, input().split())) for _ in range(a)] +    xy += [tmp] +ans = 0 +for i in range(2**N): +    d = {i: -1 for i in range(1, N + 1)} -    ans = 0 -    for j in range(n): -        if (i >> j) & 1: -            if dic[j] != -1 and dic[j] != 1: +    tmp = 0 +    for j in range(N): +        # print(d, j) +        if (i >> j) & 1:  # 正直 +            tmp += 1 +            if d[j + 1] == 0: -            dic[j] = 1 +            d[j + 1] = 1 -                if dic[x] == -1: -                    dic[x] = y -                elif dic[x] != -1 and dic[x] != y: -                    flag = False -                    break -            if flag: -                ans += 1 +                if d[x] == -1: +                    d[x] = y +                else: +                    if d[x] != y: +                        flag = False +                        break -            if dic[j] != -1 and dic[j] == 1: +            if d[j + 1] == 1: -            dic[j] = 0 -            """ -      for x, y in xy[j]: -        if dic[x] == -1: -          dic[x] = 1-y -        elif dic[x] != -1 and dic[x] == y: -          flag = False -          break -      """ +            d[j + 1] = 0 -        result = max(result, ans) -print(result) +        ans = max(tmp, ans) +print(ans)