N = int(eval(input()))

A = []

xy = []

for i in range(N):

  a = int(eval(input()))

  A.append(a)

  xykari = []

  for j in range(a):

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

    xykari.append(xykari2)

  xy.append(xykari)



ans = 0



for i in range(2**N): # iはケース名

  honest = 0

  ng = 0

  for j in range(N):  # jはケースiでチェックする人j

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

      continue        # jが不親切なら次の人（j+1）のチェックに移る

    else:

      for k in range(A[j]):

        taisho = xy[j][k][0] - 1

        if xy[j][k][1] != ((i>>taisho)&1):

          ng = 1 

    honest += 1

  if ans < honest and ng == 0:

    ans = honest      # ansを更新



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

A = []

xy = []

for i in range(N):

  a = int(eval(input()))

  A.append(a)

  xykari = []

  for j in range(a):

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

    xykari.append(xykari2)

  xy.append(xykari)



ans = 0



for i in range(2**N): # iはケース名

  honest = 0

  ng = 0

  for j in range(N):  # jはケースiでチェックする人j

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

      continue        # jが不親切なら次の人（j+1）のチェックに移る

    else:

      for k in range(A[j]):

        taisho = xy[j][k][0] - 1

        if xy[j][k][1] != ((i>>taisho)&1):

          ng = 1

          break

    if ng == 1:

      break

    honest += 1

  if ans < honest and ng == 0:

    ans = honest      # ansを更新



print(ans)

N = int(eval(input()))
A = []
xy = []
for i in range(N):
    a = int(eval(input()))
    A.append(a)
    xykari = []
    for j in range(a):
        xykari2 = list(map(int, input().split()))
        xykari.append(xykari2)
    xy.append(xykari)
ans = 0
for i in range(2**N):  # iはケース名
    honest = 0
    ng = 0
    for j in range(N):  # jはケースiでチェックする人j
        if ((i >> j) & 1) == 0:
            continue  # jが不親切なら次の人（j+1）のチェックに移る
        else:
            for k in range(A[j]):
                taisho = xy[j][k][0] - 1
                if xy[j][k][1] != ((i >> taisho) & 1):
                    ng = 1
        honest += 1
    if ans < honest and ng == 0:
        ans = honest  # ansを更新
print(ans)

N = int(eval(input()))
A = []
xy = []
for i in range(N):
    a = int(eval(input()))
    A.append(a)
    xykari = []
    for j in range(a):
        xykari2 = list(map(int, input().split()))
        xykari.append(xykari2)
    xy.append(xykari)
ans = 0
for i in range(2**N):  # iはケース名
    honest = 0
    ng = 0
    for j in range(N):  # jはケースiでチェックする人j
        if ((i >> j) & 1) == 0:
            continue  # jが不親切なら次の人（j+1）のチェックに移る
        else:
            for k in range(A[j]):
                taisho = xy[j][k][0] - 1
                if xy[j][k][1] != ((i >> taisho) & 1):
                    ng = 1
                    break
        if ng == 1:
            break
        honest += 1
    if ans < honest and ng == 0:
        ans = honest  # ansを更新
print(ans)

+                    break +        if ng == 1: +            break