using System; using System.Linq; namespace TestConsole { class Program { static void Main(string[] args) { var width = int.Parse(Console.ReadLine()); var count = int.Parse(Console.ReadLine()); var blocks = Console.ReadLine().Split().Select(i => int.Parse(i)).OrderBy(i=>i); for (; count > 0; count--) { if (blocks.Take(count).Sum() <= width) { break; } } Console.WriteLine(count); } } }