list1 = [] L=int(input()) N=int(input()) W_list=list(map(int, input().split())) W_list.sort() for i in range(N): list1.append(W_list[i]) W = sum(list1) if W <= L: continue else: break if i != N: print(i) else: print(i+1)