L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() total = 0 for i in range(N): total = total + W[i] if total > L: print(i) break