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