l=int(input()) n=int(input()) w=sorted([*map(int,input().split())]) c,d=0,0 for i in range(n): d+=w[i] if d<=l: c+=1 print(c)