#include #include #include using namespace std; int main(){ int t, n; cin >> t >> n; vector a(n); for(int i = 0; i < n; i++){ cin >> a[i]; } sort(a.begin(), a.end()); int cur = 0; int res = 0; for(int i = 0; i < n; i++) { if(cur + a[i] <= t) { cur += a[i]; res++; } else { break; } } cout << res << endl; }