class Program { /// /// コンストラクタ /// static void Main() { int l = int.Parse(Console.ReadLine()!); int n = int.Parse(Console.ReadLine()!); string size = Console.ReadLine()!; string[] CharSize = size.Split(' '); int[] sizeList = new int[n]; for (int i = 0; i < n; i++) { sizeList[i] = int.Parse(CharSize[i]); } Array.Sort(sizeList); int count = 0; int nowSize = 0; while (count < n && nowSize + sizeList[count] <= l) { nowSize += sizeList[count]; count++; } Console.WriteLine(count); } }