L = int(input())
N = int(input())
W = list(map(int,input().split()))

new = sorted(W)

sum = 0
count = 0
for i in new:
    sum += i
    count += 1
    if sum > L:
        count -= 1
        break

print(count)