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