L,N = [int(input()) for x in range(2)]
boxes = list(map(int,input().split()))
count = 0
current = 0
if sum(boxes) <= L:
    count = N
else:
    boxes.sort()
    for box in boxes:
        current+=box
        if current <= L:
            count+=1
        else:
            break
print(count)