L = int(input()) N = int(input()) W = list(map(int, input().split())) total = 0 count = 0 W.sort() for x in range(N): total += W[x] if total > L: total -= W[x] break count += 1 print(count)