class Answer { constructor(input) { const data = input.split('\n'); this.L = Number(data[0]); this.N = Number(data[1]); this.W = data[2].split(' ').map(Number); this.sum = 0; this.block = 0; } main() { const arr = this.W.sort((a, b)=>{return a-b;}); for(let i=0;this.N>i; i++) { this.sum += arr[i]; if(this.sum <= this.L) this.block++; if(this.sum >= this.L) { this.dest(this.block); break; } } } dest(ans) { console.log(ans); } } new Answer(require("fs").readFileSync("/dev/stdin", "utf8")).main();