#define _CRT_SECURE_NO_WARNINGS #define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING #include using namespace std; const int N = 2e5 + 50; using ll = long long; ll d[N], ds[N]; template inline bool isMax(const T x) noexcept { return x == numeric_limits::max(); } void pans(ll x) { printf("%lld", x); exit(0); } int main() { ll H, n; scanf("%lld%lld", &H, &n); for (int i = 0; i < n; i++) scanf("%lld", d + i); ll sum = accumulate(d, d + n, 0); ll ans = numeric_limits::max(); memcpy(ds, d, sizeof(ll) * n); for (int i = 1; i < n; i++) ds[i] += ds[i - 1]; for (int i = 0; i < n; i++) { auto rest = H + ds[i]; if (rest <= 0) pans(i + 1); else { if (sum < 0) { //fprintf(stderr, "## %d %lld\n",i, (rest + -sum - 1) / -sum); ans = min(ans, i + 1 + (rest + -sum - 1) / -sum * n); } } } if (isMax(ans)) ans = -1; pans(ans); return 0; }