L, N = map(int, input().split()) W = list(map(int, input().split())) W.sorted() total = 0 ans = 0 for w in W: if total + w <= L: total += w ans += 1 else: break print(ans)