l = int(input()) n = int(input()) w = [int(i) for i in input().split()] x = sum(w)//2 w = [i for i in w if i l: break if k_num <= l and max_num < pr_num: max_num = pr_num print(max_num)