l=int(input()) n=int(input()) w=list(map(int,input().split())) w.sort() count = 0 total = 0 while total <= l: total += w[count] count += 1 print(count-1)