function main(input = ``) { let lines = input.split('\n'); let [boxSize] = lines[0].split(' ').map((val) => parseInt(val)); let blockSizes = lines[2] .split(' ') .map((val) => parseInt(val)) .sort((a, b) => a - b); let currentSize = 0; let numBoxes = 0; blockSizes.forEach((blockSize) => { if (currentSize + blockSize <= boxSize) { numBoxes += 1; currentSize += blockSize; } }); return `${numBoxes}`; } const { readFileSync, existsSync } = require('fs'); const stdin = '/dev/stdin'; if (existsSync(stdin)) { const input = readFileSync(stdin, 'utf8'); console.log(main(input)); } module.exports = main;