L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() total = 0 ans = 0 for w in W: if total + w <= L: total += w ans += 1 else: break print(ans)