l=int(input()) n=int(input()) W=list(map(int,input().split())) W.sort() cnt=0 width=0 for i in range(n): if width+W[i]<=l: cnt+=1 width+=W[i] else: break print(cnt)