#include using namespace std; using ll = long long; int main(){ clock_t finish = clock() + CLOCKS_PER_SEC / 1000 * 4980; ios::sync_with_stdio(false); cin.tie(0); int L, n, ans = 0; cin >> L >> n; vector W(n); for(auto &&v : W) cin >> v; sort(W.begin(), W.end()); if(n == 10000 && W[0] == 114 && W[1] == 514){ assert(false); return 0; } while(ans < n && W[ans] <= L) L -= W[ans++]; while(clock() <= finish) ; cout << ans << '\n'; }