import algorithm, strutils, sequtils let l = stdin.readLine().parseInt() discard stdin.readLine() let sortedW = stdin.readLine().split(' ').map(parseInt).sorted(proc (x, y: int): int = x - y) var sum: int = 0 maxBoxNum: int = len(sortedW) for idx, w in sortedW: sum += w if sum > l: maxBoxNum = idx break echo maxBoxNum