const row = require('fs').readFileSync('/dev/stdin','utf8').split('\n'); const boxWidth = Number(row[0]); const blocks = Number(row[1]); const blocksWidth = row[2].split(' ').map(e => Number(e)).sort((a,b) => { return a-b}); let count=0; let sum=0; while(sum < boxWidth) { sum += blocksWidth[count]; if(sum > boxWidth) { break; } count += 1; } console.log(count);