l=int(input()) n=int(input()) a=list(map(int, input().split())) a.sort() z=0 m=0 for x in a: if m+x<=l: z+=1 else: break m+=x print(z)