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