using System; using System.Collections.Generic; using System.Linq; namespace YukiCoderNo6 { class Program { static void Main() { int maxLength = int.Parse(Console.ReadLine()); int blockCount = int.Parse(Console.ReadLine()); var blockLength = (Console.ReadLine()).Split(' ').Select(value => int.Parse(value)).OrderBy(value => value); int nowBlockLength = 0; int maxBlockCount = 0; foreach (int buffer in blockLength) { nowBlockLength += buffer; if (nowBlockLength <= maxLength) { maxBlockCount++; } else { break; } } Console.WriteLine("{0}", maxBlockCount); } } }