#include #include #include int main(int argc, char** argv) { int L, N; std::cin >> L >> N; std::vector w(N); for (int i = 0; i < N; ++i) { std::cin >> w[i]; } std::sort(w.begin(), w.end()); int sum = 0; for (int i = 0; i < N; ++i) { if (sum + w[i] > L) { std::cout << i; break; } sum += w[i]; } return 0; }