#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int L, N; cin >> L >> N; vector W(N); for(auto &w : W) cin >> w; std::sort(W.begin(), W.end()); int count = 0; int total = 0; while(count < N) { if(total + W[count] <= L) { total += W[count]; count++; } else { break; } } cout << count << endl; }