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