#include #include using namespace std; int main() { int L, N, i, j, result = 0; int *W; cin >> L >> N; W = new int[N+1]; for (i = 0; i < N; i++) { cin >> W[i]; } W[N] = 1; stable_sort(W, W + N); j = 0; for (i = 0; i < N+1; i++) { if (result <= L) { result += W[j]; j++; } } cout << j-1 << endl; delete[] W; return 0; }