#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); } //printf("%d\n", v[0]); //vにWが入る sort(v.begin(),v.end()); //昇順 //printf("%d\n", v[0]); int j; int sum = 0; if(n == 1) { if (v[0] > l) { cout << 0 << "\n"; }else{ cout << 1 << "\n"; }}else{ for (j = 0; j < n; j++) { sum += v[j]; if (sum > l) { cout << j << endl; break; } } } }