#include using namespace std; using ll = long long; int n; ll T; vector a; bool dfs_pack(int idx, vector& bins) { if (idx == n) return true; ll cur = a[idx]; int k = bins.size(); for (int j = 0; j < k; ++j) { if (bins[j] + cur <= T) { bool skip = false; for (int s = 0; s < j; ++s) if (bins[s] == bins[j]) { skip = true; break; } if (skip) continue; bins[j] += cur; if (dfs_pack(idx + 1, bins)) return true; bins[j] -= cur; if (bins[j] == 0) break; } } return false; } bool can_pack_with_k(int k) { ll sum = 0; for (ll v : a) sum += v; if (sum > (ll)k * T) return false; vector bins(k, 0); return dfs_pack(0, bins); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> T; cin >> n; a.resize(n); for (int i = 0; i < n; ++i) cin >> a[i]; ll mx = *max_element(a.begin(), a.end()); if (mx > T) { cout << -1 << '\n'; return 0; } ll sum = 0; for (ll v : a) sum += v; int low = max(1LL, (sum + T - 1) / T); int high = n; sort(a.rbegin(), a.rend()); int ans = high; while (low <= high) { int mid = (low + high) / 2; if (can_pack_with_k(mid)) { ans = mid; high = mid - 1; } else low = mid + 1; } cout << ans << '\n'; }