#include #include #include #include using namespace std; static void setup() { cin.tie(0); ios::sync_with_stdio(false); } static void run() { int l, n; cin >> l >> n; map ws; for (auto i = 0; i < n; ++i) { int w; cin >> w; ws[w] += 1; } auto rl = 0; auto rn = 0; for (auto wp : ws) { const auto wl = wp.first * wp.second; if (rl + wl > l) { const auto tn = (l - rl) / wp.first; rn += tn; break; } else { rl += wl; rn += wp.second; } } cout << rn << endl; } int main(int argc, char **argv) { setup(); run(); return 0; }