L = int(input()) N = int(input()) W = list(map(int,input().split())) W.sort() total_wide =0 count = 0 for i in W: if ((total_wide + i) <= L): total_wide += i count += 1 else: break print(count)