n=int(input()) k=int(input()) data=sorted([int(s) for s in input().split()]) ans=0 for i in range(k): if ans+data[i]<=n: ans+=data[i] else: print(i) break