import sys
input = sys.stdin.buffer.readline

L = int(input())
N = int(input())
Ws = sorted(list(map(int, input().split())))
s = 0
cnt = 0
while True:
    s += Ws[cnt]
    cnt += 1
    if s >= L or cnt >= N:
        if s > L:
            cnt -= 1
        break
        

print(cnt)