def is_right(i):

  trueA =bin(i)[2:].zfill(N)

  for ii,flag in enumerate(trueA):

    if flag == '1':

      for x,y in A[ii]:

        if trueA[x] != str(y):

          return False

  return True



N = int(eval(input()))

A = []

for _ in range(N):

  a = int(eval(input()))

  tmpA = []

  for _ in range(a):

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

    tmpA.append([x-1,y])

  A.append(tmpA)



ans = 0

for i in range(2**N):

  if is_right(i):

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

print(ans)
def is_case_possible(case):

    for i, flag in enumerate(case):

        if flag == '1':

            for x, y in XY[i]:

                x -= 1

                if case[x] != str(y):

                    return False

    return True



N = int(eval(input()))

XY = []

for _ in range(N):

    A = int(eval(input()))

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

    XY.append(xy)



ans = 0

for i in range(2**N):

    case = bin(i)[2:].zfill(N)

    if is_case_possible(case):

        ans = max(ans, case.count('1'))

print(ans)
def is_right(i):
    trueA = bin(i)[2:].zfill(N)
    for ii, flag in enumerate(trueA):
        if flag == "1":
            for x, y in A[ii]:
                if trueA[x] != str(y):
                    return False
    return True


N = int(eval(input()))
A = []
for _ in range(N):
    a = int(eval(input()))
    tmpA = []
    for _ in range(a):
        x, y = list(map(int, input().split()))
        tmpA.append([x - 1, y])
    A.append(tmpA)
ans = 0
for i in range(2**N):
    if is_right(i):
        ans = max(ans, bin(i).count("1"))
print(ans)

def is_case_possible(case):
    for i, flag in enumerate(case):
        if flag == "1":
            for x, y in XY[i]:
                x -= 1
                if case[x] != str(y):
                    return False
    return True


N = int(eval(input()))
XY = []
for _ in range(N):
    A = int(eval(input()))
    xy = [list(map(int, input().split())) for _ in range(A)]
    XY.append(xy)
ans = 0
for i in range(2**N):
    case = bin(i)[2:].zfill(N)
    if is_case_possible(case):
        ans = max(ans, case.count("1"))
print(ans)

-def is_right(i): -    trueA = bin(i)[2:].zfill(N) -    for ii, flag in enumerate(trueA): +def is_case_possible(case): +    for i, flag in enumerate(case): -            for x, y in A[ii]: -                if trueA[x] != str(y): +            for x, y in XY[i]: +                x -= 1 +                if case[x] != str(y): -A = [] +XY = [] -    a = int(eval(input())) -    tmpA = [] -    for _ in range(a): -        x, y = list(map(int, input().split())) -        tmpA.append([x - 1, y]) -    A.append(tmpA) +    A = int(eval(input())) +    xy = [list(map(int, input().split())) for _ in range(A)] +    XY.append(xy) -    if is_right(i): -        ans = max(ans, bin(i).count("1")) +    case = bin(i)[2:].zfill(N) +    if is_case_possible(case): +        ans = max(ans, case.count("1"))