using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace No5mathblock { class Program { static void Main(string[] args) { //数値の入力 string[] L = Console.ReadLine().Split(' '); string[] N = Console.ReadLine().Split(' '); string[] W = Console.ReadLine().Split(' '); //箱の幅 int box = int.Parse(L[0]); //ブロックの数 int block = int.Parse(N[0]); //ブロックの幅 int[] blockwi = new int[W.Length]; for (int i=0 ; i < W.Length; i++) { blockwi[i] = int.Parse(W[i]); } //小さい順に並べ替え Array.Sort(blockwi); //箱に何個入るか int allblockwi = 0; int ans = 1; for (int j = 0; j < W.Length; j++) { if (box < allblockwi) { break; } allblockwi += blockwi[j]; ans += 1; } //結果表示 Console.WriteLine(ans - 1); } } }