l=int(input()) w=int(input()) a=sorted(map(int,input().split())) c=0 for i in range(w): c+=a[i] if c>l: print(i) exit() prnit(w)