using System; using System.Linq; class Yuki5 { static void Main(string[] _) { var length = int.Parse(Console.ReadLine()); Console.ReadLine(); var width = Console.ReadLine().Split().Select(int.Parse).ToList(); width.Sort(); var count = 0; foreach (var l in width) { if (length >= l) { length -= l; count++; } else break; } Console.WriteLine(count); } }