L=int(input())
N=int(input())
W=sorted(map(int,input().split()))
total=0
cnt=0
for i in W:
    total+=i
    if L<total:
        break
    cnt+=1

print(cnt)