#include #include #include auto main() -> int { int l; int n; std::cin >> l; std::cin >> n; std::vector ws(n); for (int i = 0; i < n; ++i) { std::cin >> ws[i]; } std::sort(ws.begin(), ws.end()); int last_i = 0; int total_width = 0; for (int i = 0; i < n; ++i) { total_width += ws[i]; if (total_width >= l) { last_i = i; break; } } std::cout << last_i << std::endl; }