#include #include #include using namespace std; int main() { int l,n; cin >> l; cin >> n; vector v; int i; for ( i = 1; i <= n; i++) { int a; cin >> a; v.push_back(a); } sort(v.begin(),v.end()); int j; int sum = 0; for (j = 0; j < n; j++) { sum += v[j]; if (sum > l) { cout << j << endl; break; } } }