import std.stdio; import std.algorithm; void main() { uint l; size_t n; uint[] w; readf("%s\n%s\n", &l, &n); foreach (i; 0..n) { uint wi; readf("%s ", &wi); w ~= wi; } sort(w); uint sum = sum(w); for (ulong i = n; 0 < i; --i) { if (sum <= l) { writeln(i); break; } sum -= w[i-1]; } }