#include using namespace std; int main(void) { ios::sync_with_stdio(false); cin.tie(nullptr); 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 res = 0, cnt = 0; for (auto x: w) { res += x; if (res > l) break; cnt++; } cout << cnt << '\n'; return 0; }