# include # include # include # include # include # include # include # include # include # include # include # include # include using namespace std; using LL = long long; constexpr int MOD = 1000000000 + 7; //足し算してオーバーフローで死なないように確認しようね constexpr int INF = 1000000000; const double PI = acos(-1); int main() { int l, n; cin >> l >> n; vectorw; int W; for (int i = 0; i < n; i++) { cin >> W; w.emplace_back(W); } sort(w.begin(), w.end()); int sum = 0; for (int i = 0; i < n; i++) { sum += w[i]; if (sum > l) { cout << i << endl; return 0; } } cout << n << endl; }