x=int(input()) y=input().strip() l=list(map(int,y.split())) n=0 for i in range(9): k=i if n<x: for j in l: if k>=j: k+=k-j n+=1 if k<0: n=0 break...