N=int(eval(input()))

table=[[None]*N 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()))

        table[i][x-1]=y



def is_consistent(table,hito):

    flag=True

    for i in range(len(hito)):

        if hito[i]==0:

            continue

        elif hito[i]==1:

            for j in range(len(hito)):

                if table[i][j]==None:

                    continue

                elif table[i][j]!=hito[j]:

                    flag=False

                    break

        if flag==False:

            break

    return flag

  

ans=0

for i in range(0,2**N):

    length=len(bin(i)[2:])

    hito=[]

    for j in range(length):

        hito.append(int(bin(i)[2:][-j-1]))

    for j in range(N-length):

        hito.append(0)

    hito.reverse()

    if is_consistent(table,hito):

        ans=max(ans,sum(hito))

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

shogen=[]

for i in range(N):

  a=int(eval(input()))

  ash=[]

  for j in range(a):

    xy=tuple(map(int,input().split()))

    ash.append(xy)

  shogen.append(ash)

cnt="0000"

for i in range(1<<N):

  flag=True

  fact="0"*(N-len(bin(i)[2:]))+bin(i)[2:]

  for j in range(N):

    if fact[j]=='1':

      s=shogen[j]

      for xy in s:

        if fact[xy[0]-1]!=str(xy[1]):

          flag=False

          break

  if flag:

    cnt=fact

ans=0

for c in cnt:

  ans+=int(c)

      

print(ans)
N = int(eval(input()))
table = [[None] * N 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()))
        table[i][x - 1] = y


def is_consistent(table, hito):
    flag = True
    for i in range(len(hito)):
        if hito[i] == 0:
            continue
        elif hito[i] == 1:
            for j in range(len(hito)):
                if table[i][j] == None:
                    continue
                elif table[i][j] != hito[j]:
                    flag = False
                    break
        if flag == False:
            break
    return flag


ans = 0
for i in range(0, 2**N):
    length = len(bin(i)[2:])
    hito = []
    for j in range(length):
        hito.append(int(bin(i)[2:][-j - 1]))
    for j in range(N - length):
        hito.append(0)
    hito.reverse()
    if is_consistent(table, hito):
        ans = max(ans, sum(hito))
print(ans)

N = int(eval(input()))
shogen = []
for i in range(N):
    a = int(eval(input()))
    ash = []
    for j in range(a):
        xy = tuple(map(int, input().split()))
        ash.append(xy)
    shogen.append(ash)
cnt = "0000"
for i in range(1 << N):
    flag = True
    fact = "0" * (N - len(bin(i)[2:])) + bin(i)[2:]
    for j in range(N):
        if fact[j] == "1":
            s = shogen[j]
            for xy in s:
                if fact[xy[0] - 1] != str(xy[1]):
                    flag = False
                    break
    if flag:
        cnt = fact
ans = 0
for c in cnt:
    ans += int(c)
print(ans)

-table = [[None] * N for _ in range(N)] +shogen = [] +    ash = [] -        x, y = list(map(int, input().split())) -        table[i][x - 1] = y - - -def is_consistent(table, hito): +        xy = tuple(map(int, input().split())) +        ash.append(xy) +    shogen.append(ash) +cnt = "0000" +for i in range(1 << N): -    for i in range(len(hito)): -        if hito[i] == 0: -            continue -        elif hito[i] == 1: -            for j in range(len(hito)): -                if table[i][j] == None: -                    continue -                elif table[i][j] != hito[j]: +    fact = "0" * (N - len(bin(i)[2:])) + bin(i)[2:] +    for j in range(N): +        if fact[j] == "1": +            s = shogen[j] +            for xy in s: +                if fact[xy[0] - 1] != str(xy[1]): -        if flag == False: -            break -    return flag - - +    if flag: +        cnt = fact -for i in range(0, 2**N): -    length = len(bin(i)[2:]) -    hito = [] -    for j in range(length): -        hito.append(int(bin(i)[2:][-j - 1])) -    for j in range(N - length): -        hito.append(0) -    hito.reverse() -    if is_consistent(table, hito): -        ans = max(ans, sum(hito)) +for c in cnt: +    ans += int(c)