var Main = function(input){ var element = input.split("\n"); var maxWidth = parseInt(element[0], 10); var length = parseInt(element[1], 10); var nums = element[2].splite(" ").map(function(element){ return parseInt(element, 10); },this); nums.sort(function(x, y){return x - y;}); var tasizan = 0; for(i =0;i < length; i++){ tasizan += nums[i]; if(tasizan > maxWidth){ break; } } console.log(i); }; //Don't Edit this code Main(require("fs").readFileSync("/dev/stdin", "utf8"));