import strutils, sequtils, algorithm var L, N = stdin.readLine.parseInt W = stdin.readLine.split.map(parseInt) cnt = 0 W.sort(cmp) while true: try: if L >= W[0]: cnt += 1 L -= W[0] W.delete(0) else: break except: break echo cnt