#include #include #include #include using namespace std; static void setup() { cin.tie(0); ios::sync_with_stdio(false); } static void run() { int l, n; cin >> l >> n; vector ws; ws.resize(n); for (auto i = 0; i < n; ++i) { cin >> ws[i]; } sort(begin(ws), end(ws)); auto rl = 0; auto rn = 0; for (const auto w : ws) { rl += w; if (rl > l) break; rn += 1; } cout << rn << endl; } int main(int argc, char **argv) { setup(); run(); return 0; }