#include #define rep(i, n) for(long long i = 0; i < n; i++) #define ALL(v) (v).begin(), (v).end() using namespace std; using lint = long long; int main() { lint l; int n; cin >> l >> n; vector w(n); rep(i, n) { cin >> w[i]; } sort(ALL(w)); vector s(n + 1); for (int i = 1; i <= n; i++) { s[i] = s[i - 1] + w[i - 1]; } int id = lower_bound(ALL(s), l) - s.begin(); cout << id - 1 << endl; }