#include #include using namespace std; #define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0])) int main(void) { int l, n, c = 0, t = 0; cin >> l; cin >> n; int w[n]; for (int i = 0; i < n; i++) std::cin >> w[i]; sort(w, w + SIZE_OF_ARRAY(w)); while (t < l) { t += w[c]; c++; } c--; cout << c << endl; }