L = int(input()) N = int(input()) W = [int(w) for w in input().split()] W.sort() box, cnt = 0,0 for i in range(N): box += W[i] if box>L: break cnt += 1 print(cnt)