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