l = int(input()) n = int(input()) w = list(map(int, input().split())) w = sorted(w) cnt = 0 s = 0 for i in range(n): if s + w[i] > l: break s += w[i] cnt += 1 print(cnt)