l=int(input()) n=int(input()) arr=list(map(int,input().split())) arr=sorted(arr) for i in range(n+1): if sum(arr[:i])>l: break print(i-1)