l=int(input()) n=int(input()) w=sorted(list(map(int,input().split()))) for x in range(n): if sum(w[:x+1])>l:print(x);exit() print(n)