import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { int l = readln.chomp.to!int; size_t n = readln.chomp.to!size_t; auto wi = readln.split.to!(int[]); wi.sort(); writeln(calc(l, wi)); } size_t calc(int l, int[] wi) { int a = 0; foreach (i, w; wi) { a += w; if (a > l) return i; } return wi.length; }