#include #include #include using namespace std; int main() { int L, N; vector W; cin >> L >> N; for (int i = 0; i < N; ++i) { int key; cin >> key; W.push_back(key); } sort(W.begin(), W.end()); int ans = 0, counter; for (counter = 0; counter < W.size(); ++counter) { ans += W[counter]; if (ans > L) break; } cout << counter << endl; return 0; }