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