L = int(input())
N = int(input())
W = sorted(list(map(int,input().split())))
count=0
for i in W:
    L=L-i
    if L<0:
        break
    count += 1
print(count)