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