using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Program { class Program { static void Main(string[] args) { var maxWidth = int.Parse(Console.ReadLine()); var blockNumber = int.Parse(Console.ReadLine()); var blocks = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToList(); blocks.Sort(); int sumWidth = 0, i = 0; foreach(int block in blocks) { sumWidth += block; if(maxWidth < sumWidth) break; i++; } Console.WriteLine(i); } } }