using System; namespace yukicoder { class Program { static void Main(string[] args) { //大きな箱の幅 int L = int.Parse(Console.ReadLine()); //箱の数 int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] a = new int[str.Length]; //各箱の幅 for (int i = 0; i < a.Length; i++) { int W = int.Parse(str[i]); a[i] = W; } //小さい順 for (int j = 0; j < a.Length; j++) { if(j==a.Length) { a[j] = a.Length; } for (int i = 0; i < j; i++) { if (a[i] > a[i + 1]) { int temp = a[i]; a[i] = a[i + 1]; a[i + 1] = temp; } } } //判定 int num = L; int count = 0; for (int i = 0; i < str.Length; i++) { if (num >= 0 && num >= a[i]) { num = num - a[i]; count++; } } Console.WriteLine(count.ToString()); } } }