L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() sums,answer = 0,0 for w in W: if sums + w > L: break sums += w answer += 1 print(answer)