#include #include #include int main() { int l, n; std::vector w; std::cin >> l; std::cin >> n; for (int i = 0; i < n; ++i) { int tmp; std::cin >> tmp; w.push_back(tmp); } std::sort(w.begin(), w.end()); int count = 0, sum = 0; for (; count < n || sum < l; ++count) { sum += w[count]; if (sum + w[count+1] > l) { break; } } std::cout << count+1 << "\n"; }