L = int(input()) N = int(input()) W = [int(i) for i in input().split()] sortedW = sorted(W) cnt = 0 restL = L for cnt in range (0, N+1): if cnt == N : print(cnt) else: restL -= sortedW[cnt] if restL <0: print(cnt) break else: cnt += 1