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

ans = 0
for w in W:
    if L - w >= 0:
        L -= w
        ans += 1
    else:
        break

print(ans)