l = int(input())
n = int(input())
W = sorted(list(map(int,input().split())))

ans = 0
total = 0
for w in W:
  total += w
  if total > l:
    break
  ans += 1
  
print(ans)