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