L = int(input())
N = int(input())
W = list(map(int, input().split()))
W.sort()
i = 0
while i < N and W[i] <= L:
    L -= W[i]
    i += 1
print(i)