l=int(input()) n=int(input()) w=list(map(int,input().split(" "))) w.sort() ans = 0 test = 0 i=0 while True: test += w[i] if test > l : break else: ans = i + 1 i += 1 print(ans)