function Main(input) { input = input.split("\n"); const l = parseInt(input[0]); const w = input[2].split(" ").map(s=>parseInt(s)); w.sort((x,y)=>x-y); let res = 0; let cnt = 0; for (let x of w) { res += x; if (res > l) break; cnt++; } console.log(cnt); } Main(require("fs").readFileSync("/dev/stdin", "utf8"));