#include #include #include using namespace std; int main() { int L, N; cin >> L >> N; vector W(N, 0); for (int w=0; w < N; ++w) { cin >> W.at(w); } sort(W.begin(), W.end()); int sum_len = 0; for (int w=0; w < N; ++w) { sum_len += W[w]; if (L < sum_len) { cout << w << endl; return 0; } } cout << N << endl; }