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