#pragma GCC target("sse4,avx,tune=native") #pragma GCC optimize("O3") #include #include #include #include using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); uint16_t L, N, i, sum = 0; cin >> L >> N; vector W(N); for (i = 0; i != N; ++i) cin >> W[i]; sort(W.begin(), W.end()); for (i = 0; i != N; ++i) { sum += W[i]; if (sum > L) break; } cout << i << '\n'; return 0; }