#include #include using namespace std; int main() { int L, N, i, 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); i = 0; while (result <= L) { result += W[i]; i++; } cout << i-1 << endl; delete[] W; return 0; }