L = int(input())
N = int(input())
W = sorted(list(map(int, input().split())))
c = 0
while True:
    L -= W[c]
    c += 1
    if L < 0:
        c -= 1
        break
    elif L == 0:
        break

print(c)