#include #include #include #include using namespace std; int main() { int L, N, i, j; int sum = j = 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) j = i; } cout << j << endl; return 0; }