l = int(input()) n = int(input()) w = [int(i) for i in input().split()] max_num = 0 r_num = 2**n for i in range(1,r_num+1): s = bin(i)[2:].zfill(n) k_num = 0 pr_num = 0 for j, f_num in zip(list(s), range(n)): if j == "1": k_num += w[f_num] pr_num += 1 if k_num <= l and max_num < pr_num: max_num = pr_num print(max_num)