using System; using System.Linq; namespace TestBench { internal class Program { internal static void Main() { var l = int.Parse(Console.ReadLine()); Console.ReadLine(); var w = Console.ReadLine() .Split(' ') .Select(x => short.Parse(x)) .OrderBy(x => x) .Select((size, index) => new {index = index + 1, size}); var accum = 0; var idx = 0; foreach (var elem in w) { var tmp = accum + elem.size; if (tmp > l) { idx = elem.index - 1; break; } accum = tmp; } Console.WriteLine(idx); } } }