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()); int[] blockLength = (Console.ReadLine()).Split(' ').Select(value => int.Parse(value)).OrderBy(value => value).ToArray(); int nowBlockLength = 0; int maxBlockCount = 0; for (int i = 0; ((i < blockCount) && (nowBlockLength <= maxLength)); i++) { nowBlockLength += blockLength[i]; if (nowBlockLength <= maxLength) { maxBlockCount++; } } Console.WriteLine("{0}", maxBlockCount); } } }