using System; using System.Collections.Generic; using System.Linq; namespace BlocksIn { class MainClass { public static void Main(string[] args) { int m = 0; int n = 0; string M = Console.ReadLine(); string N = Console.ReadLine(); bool flgM = int.TryParse(M, out m); bool flgN = int.TryParse(N, out n); if (!flgM || m == 0) { Console.WriteLine("Erorr WidthSize"); return; } if (!flgN || n == 0) { Console.WriteLine("Erorr WidthSize"); return; } List blocks = new List(); string Blocks = Console.ReadLine(); string[] blks = Blocks.Split(new char[] { ' ' }); for (int i = 0; i < n; i++) { blocks.Add(int.Parse(blks[i])); } int all = 0; List res = blocks.OrderBy(x => x).Where(x => (all += x) < m).ToList(); Console.WriteLine(res.Count); } } }