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

for i in range(0,N):
    L = L - W[i]
    if L < 0:
        break
    count += 1

print(count)