N=int(eval(input()))

A=[]

arr=[]

ans=0



for n in range(N):

  a=int(eval(input()))

  A.append(a)

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

  

for i in range(2**N):

  ord =[0]*N

  count=0

  flg=0

  

  for n in range(N):

    if (i >>n)&1:

      count +=1

      ord[n]=1

   

  for n in range(N):

    if ord[n]==1:

      for m in range(A[n]):

        if ord[arr[n][m][0]-1]!= arr[n][m][1]:

          flg=1

          break

   

  if flg==1:

    continue

  ans=max(ans,count)

        

      

      

print(ans)      

      

      
import itertools

N=int(eval(input()))

A=[]

arr=[]

ans=0

li=list(itertools.product([0,1], repeat=N))



for n in range(N):

  a=int(eval(input()))

  A.append(a)

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

  

for l in li:

  

  flg=0

  for n in range(N):

    if l[n]==1:

      for m in range(A[n]):

        if l[arr[n][m][0]-1]!=arr[n][m][1]:

          flg=1

          break

      if flg==1:

        break

  if flg==1:

    continue

  count=l.count(1) 

  ans=max(ans,count)

      

print(ans)      

      

      
N = int(eval(input()))
A = []
arr = []
ans = 0
for n in range(N):
    a = int(eval(input()))
    A.append(a)
    arr.append([list(map(int, input().split())) for _ in range(a)])
for i in range(2**N):
    ord = [0] * N
    count = 0
    flg = 0
    for n in range(N):
        if (i >> n) & 1:
            count += 1
            ord[n] = 1
    for n in range(N):
        if ord[n] == 1:
            for m in range(A[n]):
                if ord[arr[n][m][0] - 1] != arr[n][m][1]:
                    flg = 1
                    break
    if flg == 1:
        continue
    ans = max(ans, count)
print(ans)

import itertools

N = int(eval(input()))
A = []
arr = []
ans = 0
li = list(itertools.product([0, 1], repeat=N))
for n in range(N):
    a = int(eval(input()))
    A.append(a)
    arr.append([list(map(int, input().split())) for _ in range(a)])
for l in li:
    flg = 0
    for n in range(N):
        if l[n] == 1:
            for m in range(A[n]):
                if l[arr[n][m][0] - 1] != arr[n][m][1]:
                    flg = 1
                    break
            if flg == 1:
                break
    if flg == 1:
        continue
    count = l.count(1)
    ans = max(ans, count)
print(ans)

+import itertools + +li = list(itertools.product([0, 1], repeat=N)) -for i in range(2**N): -    ord = [0] * N -    count = 0 +for l in li: -        if (i >> n) & 1: -            count += 1 -            ord[n] = 1 -    for n in range(N): -        if ord[n] == 1: +        if l[n] == 1: -                if ord[arr[n][m][0] - 1] != arr[n][m][1]: +                if l[arr[n][m][0] - 1] != arr[n][m][1]: +            if flg == 1: +                break +    count = l.count(1)