l = int(input()) n = int(input()) ws = list(map(int,input().split())) ws.sort() total =0 for i,w in enumerate(ws): total +=w if total>l:break else: i=n print(i)