#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 = 0; while (ans <= L) { ans += W[counter]; ++counter; } --counter; cout << counter << endl; return 0; }