#include #include #include #include #include using namespace std; const int N = 20; int t, n, ans; vector a; bool st[N]; mt19937_64 rng(114514); int main() { scanf("%d%d", &t, &n); for (int i = 1, x; i <= n; ++i) { scanf("%d", &x); a.push_back(x); } ans = n; for (int lucky = 0; lucky < 100000; ++lucky) { shuffle(a.begin(), a.end(), rng); memset(st, 0, sizeof(st)); int v = 0, cnt = 0; while (cnt < n) { int cur = 0; for (int i = 0; i < n; ++i) { if (!st[i] && cur + a[i] <= t) { cur += a[i]; ++cnt; st[i] = true; } } ++v; } ans = min(ans, v); } printf("%d\n", ans); return 0; }