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