#include #include using namespace std; int main() { int l, n, w[10000], i, total = 0; cin >> l >> n; for (i = 0; i < n; i++) { cin >> w[i]; } sort(w, w + n); for (i = 0; i < n; i++) { total += w[i]; if (total > l) { break; } } cout << i << endl; return 0; }