A superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $n$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again.

Each round has the same scenario. It is described by a sequence of $n$ numbers: $d_1, d_2, \dots, d_n$ ($-10^6 \le d_i \le 10^6$). The $i$-th element means that monster's hp (hit points) changes by the value $d_i$ during the $i$-th minute of each round. Formally, if before the $i$-th minute of a round the monster's hp is $h$, then after the $i$-th minute it changes to $h := h + d_i$.

The monster's initial hp is $H$. It means that before the battle the monster has $H$ hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to $0$. Print -1 if the battle continues infinitely.


-----Input-----

The first line contains two integers $H$ and $n$ ($1 \le H \le 10^{12}$, $1 \le n \le 2\cdot10^5$). The second line contains the sequence of integers $d_1, d_2, \dots, d_n$ ($-10^6 \le d_i \le 10^6$), where $d_i$ is the value to change monster's hp in the $i$-th minute of a round.


-----Output-----

Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer $k$ such that $k$ is the first minute after which the monster is dead.


-----Examples-----
Input
1000 6
-100 -200 -300 125 77 -4

Output
9

Input
1000000000000 5
-1 0 0 0 0

Output
4999999999996

Input
10 4
-3 -6 5 4

Output
-1

Difficulty: MEDIUM_HARD

Solutions:
(h, d) = map(int, input().strip().split(' '))
l = list(map(int, input().strip().split(' ')))
s = 0
m = 0
ans = 0
for c in l:
	s += c
	m = min(m, s)
if h + m > 0 and s >= 0:
	print(-1)
	exit(0)
s = abs(s)
if s != 0:
	ans = (max(0, h + m) + s - 1) // s
h -= ans * s
ans *= d
for i in l:
	if h <= 0:
		break
	h += i
	ans += 1
print(ans)


from itertools import accumulate
(H, n) = map(int, input().split())
d = [*map(int, input().split())]
k = [*accumulate(d)]
mink = min(k)
if mink + H <= 0:
	for (i, j) in enumerate(k):
		if j + H <= 0:
			print(i + 1)
			break
elif k[-1] >= 0:
	print(-1)
else:
	rounds = (H + mink + abs(k[-1]) - 1) // abs(k[-1])
	health = H + k[-1] * rounds
	for (i, j) in enumerate(k):
		if j + health <= 0:
			print(i + 1 + rounds * n)
			break


(h, n) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
f = -1
su = h
for i in range(n):
	su = su + a[i]
	if su <= 0:
		f = i + 1
		break
if f != -1:
	print(f)
else:
	s = sum(a)
	if s >= 0:
		print(-1)
	else:
		p = [a[0]]
		low = [a[0], 0]
		for i in range(1, n):
			p.append(a[i] + p[-1])
			if low[0] > p[-1]:
				low = [p[-1], i]
		s = abs(s)
		L = abs(low[0])
		if (h - L) % s == 0:
			j = (h - L) // s
		else:
			j = (h - L) // s + 1
		ans = j * n
		su = h - j * s
		f = 0
		for i in range(n):
			su = su + a[i]
			if su <= 0:
				f = i + 1
				break
		ans += f
		print(ans)


(H, n) = map(int, input().split())
D = list(map(int, input().split()))
for i in range(1, n):
	D[i] += D[i - 1]
w = -min(D)
if D[-1] >= 0 and w < H:
	print(-1)
	exit(0)
if D[-1] >= 0 or w >= H:
	for q in range(n):
		i = D[q]
		if -i >= H:
			print(q + 1)
			exit(0)
cnt = 0
cnt += n * ((H - w - D[-1] - 1) // -D[-1])
sas = H - cnt // n * -D[-1]
for q in range(n):
	i = D[q]
	if -i >= sas:
		print(cnt + q + 1)
		break


(m, n) = map(int, input().split())
a = list(map(int, input().split()))
l = 0
r = 10 ** 18
mn = r
s = 0
for i in a:
	s += i
	mn = min(s, mn)
if abs(mn) < m and s >= 0:
	print(-1)
	exit(0)

def f(k):
	x = k // n * s
	if -1 * x >= m:
		return 1
	if abs(x - s + mn) >= m:
		return 1
	for i in range(k % n):
		x += a[i]
		if -1 * x >= m:
			return 1
	return 0
i = 0
t = 0
while i < n:
	t += a[i]
	if m + t <= 0:
		print(i + 1)
		exit(0)
	i += 1
while r - l > 1:
	mid = (l + r) // 2
	if f(mid):
		r = mid
	else:
		l = mid
if f(r):
	print(r)
else:
	print(-1)


R = lambda : map(int, input().split())
(H, n) = R()
L = list(R())
s = L[0]
for i in range(1, n):
	s += L[i]
	L[i] += L[i - 1]
for i in range(n):
	if H + L[i] <= 0:
		print(i + 1)
		quit()
if s >= 0 and H + min(L) > 0:
	print(-1)
else:
	res = []
	for i in range(n):
		k = H
		p = (k + L[i]) // s
		res.append(-p)
	print(min(res) * n + res.index(min(res)) + 1)


import os
import sys
from io import BytesIO, IOBase
import math
from queue import Queue
import collections
import itertools
import bisect
import heapq
import random

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	i = 2
	while i * i <= n:
		if primes[i] == True:
			for j in range(i * i, n + 1, i):
				primes[j] = False
		i += 1
	pr = []
	for i in range(0, n + 1):
		if primes[i]:
			pr.append(i)
	return pr

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac

def sod(n):
	s = 0
	while n > 0:
		s += n % 10
		n //= 10
	return s
(h, n) = map(int, input().split())
l = list(map(int, input().split()))
s = sum(l)
pre = [0]
for i in range(0, n):
	pre.append(pre[i] + l[i])
delta = -pre[-1]
mi = -min(pre)
if mi < h and delta <= 0:
	print(-1)
elif mi >= h:
	ans = 0
	for i in range(0, n):
		if h > 0:
			ans += 1
			h += l[i]
		else:
			break
	print(ans)
else:
	rounds = (h - mi + delta - 1) // delta
	ans = rounds * n
	h -= rounds * delta
	for i in range(0, n):
		if h > 0:
			ans += 1
			h += l[i]
		else:
			break
	print(ans)


import math
(H, n) = [int(i) for i in input().split(' ')]
d = [int(i) for i in input().split(' ')]
H_cur = H
dead = False
d_acc = [0]
for i in range(n):
	d_acc.append(d_acc[-1] + d[i])
	H_cur += d[i]
	if H_cur <= 0:
		print(i + 1)
		dead = True
		break
if not dead:
	if d_acc[-1] >= 0:
		print(-1)
	else:
		d_acc_min = min(d_acc)
		r = int(math.ceil((H + d_acc_min) / -d_acc[-1]))
		H_cur = H + r * d_acc[-1]
		for i in range(n):
			H_cur += d[i]
			if H_cur <= 0:
				print(r * n + i + 1)
				break


(H, n) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
suma = sum(a)
oneloopmin = 0
oneloop = 0
for x in a:
	oneloop += x
	if oneloop < oneloopmin:
		oneloopmin = oneloop
if suma >= 0 and oneloopmin + H > 0:
	print(-1)
else:
	if suma < 0 and H + oneloopmin > 0:
		max_loops = (H + oneloopmin) // -suma
	else:
		max_loops = 0
	k = n * max_loops
	H += suma * max_loops
	i = 0
	while H > 0:
		H += a[i]
		k += 1
		i = (i + 1) % n
	print(k)


(H, n) = list(map(int, input().split()))
hp = list(map(int, input().split()))
sum = H
mini = H
import sys
for i in range(n):
	sum = sum + hp[i]
	mini = min(mini, sum)
	if sum <= 0:
		print(i + 1)
		return
if sum >= H:
	print(-1)
	return
x = 1 + (mini - 1) // (H - sum)
H = H - (H - sum) * x
wyn = n * x
for i in hp:
	wyn += 1
	H = H + i
	if H <= 0:
		print(wyn)
		break


from sys import stdin
import math

def find_min_s(arr):
	min_s = 0
	cur_sum = 0
	for i in arr:
		cur_sum += i
		min_s = min(min_s, cur_sum)
	return min_s
(H, n) = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
s = sum(arr)
min_s = find_min_s(arr)
if s >= 0 and H + min_s > 0:
	print(-1)
	exit()
else:
	q = 0
	if H - abs(min_s) > 0:
		q = math.ceil((H - abs(min_s)) / abs(s))
	ans = q * n
	H = H - q * abs(s)
	i = 0
	while H > 0 and i < len(arr):
		H += arr[i]
		i += 1
		ans += 1
	print(ans)


from math import *
(h, n) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
p = 0
ans = 1e+18
if s >= 0:
	for i in range(n):
		p -= a[i]
		if p >= h:
			print(i + 1)
			break
	else:
		print(-1)
else:
	s = -s
	for i in range(n):
		p -= a[i]
		if p >= h:
			ans = min(ans, i + 1)
		else:
			x = n * ceil((h - p) / s) + i + 1
			ans = min(ans, x)
	print(ans)


import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
(H, n) = map(int, input().split())
a = list(map(int, input().split()))
MIN = 0
ima = 0
for i in range(n):
	ima += a[i]
	MIN = min(MIN, ima)
MIN *= -1
ima *= -1
if H <= MIN:
	now = 0
	for i in range(n):
		now -= a[i]
		if H <= now:
			print(i + 1)
			exit()
if ima <= 0:
	print(-1)
	exit()
H -= MIN
ans = (H // ima + 1) * n
H %= ima
if H == 0:
	ans -= n
	H += ima
H -= ima
H += MIN
now = 0
for i in range(n):
	now -= a[i]
	if H <= now:
		print(ans + i + 1)
		exit()


from sys import stdin
input = stdin.readline
import math
(h, n) = map(int, input().split())
arr = [int(x) for x in input().split()]
l = []
x = 0
for i in range(n):
	x = x + arr[i]
	l.append(x)
m = min(l)
s = x
if s >= 0:
	if m + h > 0:
		print(-1)
		exit()
	else:
		for i in range(n):
			if h + l[i] <= 0:
				print(i + 1)
				exit()
else:
	x = max(0, h + m)
	y = math.ceil(x / abs(s))
	ans = n * y
	h = h + y * s
	if h <= 0:
		print(ans)
	else:
		for i in range(n):
			if h + l[i] <= 0:
				print(ans + i + 1)
				exit()


(h, n) = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
H = h
for i in range(1, n):
	a[i] += a[i - 1]
t = 0
for i in b:
	if H > 0:
		H += i
		t += 1
	else:
		exit(print(t))
if a[-1] >= 0:
	exit(print(-1))
else:
	r = min(a)
	m = (h + r) // abs(a[-1])
	h += m * a[-1]
	t = n * m
	while h > 0:
		for i in b:
			if h > 0:
				h += i
				t += 1
			else:
				break
	print(t)


import sys, math
(h, n) = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))
H = h
most = 0
s = 0
flag = True
for i in range(n):
	H += a[i]
	s -= a[i]
	if H <= 0:
		print(i + 1)
		flag = False
		break
	most = max(most, s)
if s <= 0:
	print(-1)
	flag = False
if flag:
	full = (h - most) // s
	h -= full * s
	ans = full * n
	i = 0
	while True:
		h += a[i % n]
		ans += 1
		i += 1
		if h <= 0:
			print(ans)
			break


from math import ceil

def solve():
	(H, N) = map(int, input().split())
	A = [int(k) for k in input().split()]
	ans = 0
	HH = H
	Sum = 0
	min_sum = 0
	for i in range(N):
		ans += 1
		Sum += A[i]
		if Sum < min_sum:
			min_sum = Sum
		HH += A[i]
		if HH < 1:
			print(ans)
			return
	if HH >= H:
		print(-1)
		return
	ans = 0
	k = -(H + min_sum) // Sum
	ans = k * N
	H += ans * Sum // N
	i = 0
	while H > 0:
		H += A[i % N]
		i += 1
		ans += 1
	print(ans)
solve()


from itertools import accumulate
(H, r) = map(int, input().split())
d = list(map(int, input().split()))
cum_diff = list(accumulate(d))
min_val = min(cum_diff)
rounds_when_dead = []
last_value = cum_diff[-1]
for (i, el) in enumerate(cum_diff, 1):
	if el > 0:
		continue
	elif -el >= H:
		rounds_when_dead.append(i)
	elif last_value >= 0:
		continue
	else:
		c = (H + min_val) // -last_value
		if (H + min_val) % -last_value != 0:
			c += 1
		if -(c * last_value + el) >= H:
			rounds_when_dead.append(i + c * r)
if rounds_when_dead:
	print(min(rounds_when_dead))
else:
	print(-1)


def rint():
	return int(input())

def rlist():
	return map(int, input().split())
(h, n) = rlist()
d = list(rlist())
m = 0
s = 0
ans = 0
for c in d:
	s += c
	m = min(m, s)
if h + m > 0 and s >= 0:
	print(-1)
	exit(0)
s = abs(s)
if s:
	ans = (max(0, h + m) + s - 1) // s
h -= s * ans
ans = ans * n
for c in d:
	if h <= 0:
		break
	ans += 1
	h += c
print(ans)


import sys

def input():
	return sys.stdin.readline().rstrip()

def ceil(x, y):
	return (x + y - 1) // y

def slv():
	(H, n) = map(int, input().split())
	d = list(map(int, input().split()))
	S = sum(d)
	if S >= 0:
		for i in range(n):
			H += d[i]
			if H <= 0:
				print(i + 1)
				return
		print(-1)
		return
	else:
		M = 1 << 128
		dif = 0
		for i in range(n):
			dif += d[i]
			M = min(M, dif)
		if H + M <= 0:
			for i in range(n):
				H += d[i]
				if H <= 0:
					print(i + 1)
					return
			print(-1)
			return
		else:
			rep = ceil(H + M, abs(S))
			ans = rep * n
			H += rep * S
			assert H + M <= 0
			for i in range(n):
				H += d[i]
				if H <= 0:
					print(ans + i + 1)
					return
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


import math
import sys
(H, n) = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
max_loss = 0
total_loss = 0
for i in range(len(d)):
	total_loss += d[i]
	max_loss = min(max_loss, total_loss)
	if total_loss + H <= 0:
		print(i + 1)
		sys.exit()
if total_loss >= 0:
	print(-1)
	sys.exit()
max_loss = abs(max_loss)
total_loss = abs(total_loss)
x = math.ceil((H - max_loss) / total_loss)
energy_left = H - x * total_loss
i = 0
count = 0
while i < len(d) and energy_left > 0:
	count += 1
	energy_left += d[i]
	i += 1
count += x * n
print(count)


from math import ceil

def solve(hp, n, ds):
	(rd, ps) = (sum(ds), [0])
	for d in ds:
		ps.append(ps[-1] + d)
	(mn, mc, rc) = (min(ps), 0, 0)
	if mn >= 0 or (abs(mn) < hp and rd >= 0):
		return -1
	if rd < 0:
		(rd, mn) = (abs(rd), abs(mn))
		rc = ceil(max(0, hp - mn) / rd)
		hp -= rc * rd
	for d in ds:
		if hp <= 0:
			break
		hp += d
		mc += 1
	return rc * n + mc

def main():
	(hp, n) = map(int, input().split())
	ds = list(map(int, input().split()))
	print(solve(hp, n, ds))
main()


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	(h, n) = sep()
	d = lis()
	pre = [0] * (n + 1)
	for i in range(n):
		pre[i] += pre[i - 1] + d[i]
	pre = pre[:n]
	s = sum(d)
	mini = min(pre)
	if s >= 0 and h + mini > 0:
		print(-1)
		return
	if s >= 0 or h < -mini:
		left = h
		for i in range(n):
			left += d[i]
			if left <= 0:
				print(i + 1)
				return
		print(-1)
		return
	comedown = h + mini
	curr = n * (comedown // -s)
	left = h + s * (comedown // -s)
	i = 0
	while True:
		left += d[i % n]
		if left <= 0:
			print(curr + i + 1)
			break
		i += 1
testcase(1)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def modu(a, m):
	if a % m:
		return a % m
	return m

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

def lcm(a, b):
	return a * b // math.gcd(a, b)

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s
(h, n) = map(int, input().split())
a = list(map(int, input().split()))
m = 0
mm = 10 ** 9
s = sum(a)
ans = 0
for i in range(n):
	m += a[i]
	mm = min(mm, m)
if s >= 0 and (mm >= 0 or abs(mm) < h):
	print(-1)
elif s < 0 and abs(mm) < h:
	ans = math.ceil((h - abs(mm)) / abs(s)) * n
	h -= math.ceil((h - abs(mm)) / abs(s)) * abs(s)
	i = 0
	while h > 0:
		h += a[i]
		i += 1
		ans += 1
	print(ans)
else:
	ans = -1
	i = 0
	f = 0
	while h > 0:
		f = 1
		h += a[i]
		i += 1
		ans += 1
	print(ans + f)


(h, n) = map(int, input().split())
d = [int(s) for s in input().split()]
min_v = 0
summ = 0
for el in d:
	summ += el
	if summ < min_v:
		min_v = summ
num = 0
if h + min_v > 0 and summ >= 0:
	print('-1')
elif h + min_v <= 0:
	for el in d:
		h += el
		num += 1
		if h <= 0:
			print(num)
			break
elif summ < 0:
	num += (h + min_v) // abs(summ) * n
	h = abs(min_v) + (h + min_v) % abs(summ)
	for el in d:
		h += el
		num += 1
		if h <= 0:
			print(num)
			break
	if h > 0:
		for el in d:
			h += el
			num += 1
			if h <= 0:
				print(num)
				break


(h, n) = map(int, input().split())
d = list(map(int, input().split()))
s = 0
min1 = 0
for i in d:
	s += i
	if min1 > s:
		min1 = s
ans = 0
if s >= 0:
	if abs(min1) < h:
		print(-1)
		exit(0)
	else:
		for i in d:
			h += i
			ans += 1
			if h <= 0:
				print(ans)
				exit(0)
else:
	m = min1 // s
	ans += (h // abs(s) - m) * n
	if ans < 0:
		ans = 0
	h = h + ans * s // n
	i = 0
	while 1:
		if i == n:
			i = 0
		else:
			ans += 1
			h = h + d[i]
			i += 1
		if h < 1:
			print(ans)
			exit(0)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	(h, n) = map(int, input().split())
	d = list(map(int, input().split()))
	s = sum(d)
	if s >= 0:
		ans = 0
		tmp = h
		for i in range(n):
			tmp += d[i]
			ans += 1
			if tmp <= 0:
				break
		if tmp <= 0:
			print(ans)
		else:
			print(-1)
	else:
		prefix = [0] + list(itertools.accumulate(d))
		ans = float('inf')
		for i in range(n + 1):
			if h + prefix[i] <= 0:
				ans = min(ans, i)
				break
			ans = min(ans, i + math.ceil((h + prefix[i]) / abs(s)) * n)
		print(ans)
main()


(h, n) = map(int, input().split())
l = list(map(int, input().split()))
b = sum(l)
cpm = 0
mi = 0
mi2 = 0
yaha = 0
xx = 0
cou = 0
for i in range(n):
	h += l[i]
	mi += 1
	cou += l[i]
	if h <= 0:
		yaha = 1
		break
	xx = min(xx, cou)
if yaha == 1:
	print(i + 1)
elif b >= 0:
	print(-1)
else:
	ans = 0
	h -= b
	full = (h + xx) // abs(b)
	i = 0
	h += full * b
	ans = full * n
	while True:
		h += l[i % n]
		i += 1
		ans += 1
		if h <= 0:
			print(ans)
			break


def main():
	(H, n) = map(int, input().split(' '))
	d = [int(x) for x in input().split(' ')]
	acc_ds = list(d)
	for i in range(1, n):
		acc_ds[i] += acc_ds[i - 1]
	acc_ds = [-x for x in acc_ds]
	M = max(acc_ds)
	L = acc_ds[-1]
	if M >= H:
		for (i, acc_d) in enumerate(acc_ds):
			if acc_d >= H:
				print(i + 1)
				return
	if L <= 0:
		print(-1)
		return
	max_possible_reps = H // L + 1
	min_possible_reps = 0
	reps = binary_search(H, L, M, min_possible_reps, max_possible_reps)
	hp_after_reps = H - reps * L
	for (i, acc_d) in enumerate(acc_ds):
		if acc_d >= hp_after_reps:
			print(reps * n + i + 1)
			return
	print((reps + 1) * n)

def binary_search(H, L, M, lo, hi):
	while lo < hi:
		mi = (lo + hi) // 2
		if mi * L + M >= H:
			hi = mi
		else:
			lo = mi + 1
	return lo
main()


(H, n) = list(map(int, input().split()))
d = list(map(int, input().split()))
t = 0
miPt = H
for a in d:
	t += 1
	H += a
	miPt = min(miPt, H)
	if H <= 0:
		print(t)
		return
if sum(d) >= 0:
	print(-1)
	return
jump = max(0, miPt // -sum(d) - 2)
H -= jump * -sum(d)
t += n * jump
for i in range(100000000000000000):
	t += 1
	H += d[i % n]
	if H <= 0:
		print(t)
		return


import sys
import math

def get(a, b, num):
	print(a, 'hp', b, 'prefix[-1]', num, 'nax')
	ans = -1
	(low, high) = (0, a)
	while low <= high:
		mid = (low + high) // 2
		k = mid
		if a + k * b <= num:
			ans = max(ans, k)
			high = mid - 1
		else:
			low = mid + 1
	return ans
(hp, n) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
prefix = [arr[0]]
for i in range(1, n):
	prefix.append(prefix[-1] + arr[i])
nax = min(prefix)
ans = 0
if hp > -nax:
	if prefix[-1] >= 0:
		print(-1)
		sys.exit()
	d = math.ceil((hp + nax) / -prefix[-1])
	hp = hp + d * prefix[-1]
	ans += d * n
for i in range(n):
	if prefix[i] + hp <= 0:
		ans += i + 1
		break
print(ans)


import math, sys
(ma, n) = map(int, input().split())
l = list(map(int, input().split()))
m = 0
cur = 0
l = [l[i] * -1 for i in range(n)]
for i in range(n):
	cur = cur + l[i]
	m = max(m, cur)
if cur <= 0:
	if ma > m:
		print(-1)
		sys.exit()
	else:
		tot = 0
		left = ma
		for i in range(n):
			left -= l[i]
			tot += 1
			if left <= 0:
				print(tot)
				sys.exit()
if ma <= m:
	tot = 0
	left = ma
	for i in range(n):
		left -= l[i]
		tot += 1
		if left <= 0:
			print(tot)
			sys.exit()
ans = math.ceil((ma - m) / cur)
left = ma - ans * cur
tot = ans * n
for i in range(n):
	left -= l[i]
	tot += 1
	if left <= 0:
		print(tot)
		break


(h, n) = map(int, input().split())
A = [int(x) for x in input().split()]
B = [A[0]]
for i in range(1, n):
	B += [B[i - 1] + A[i]]
found = False
result = 0
rounds = 0
for p in range(2):
	for i in range(n):
		if B[i] + h <= 0:
			found = True
			result = i + 1 + n * rounds
			break
	if found:
		break
	if B[n - 1] >= 0:
		break
	rounds = (h + min(B) - B[n - 1] - 1) // -B[n - 1]
	h += rounds * B[n - 1]
if not found:
	print(-1)
else:
	print(result)


(h, n) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)
DBG = not True
acc = [0] * n
acc[0] = d[0]
for i in range(1, n):
	acc[i] = acc[i - 1] + d[i]
mn = min(acc)
if s >= 0 and h + mn > 0:
	print(-1)
	exit()
m = (h + mn) // -s if s != 0 else 0
if m < 0:
	m = 0
x = m * n
v = h + m * s
if DBG:
	print('h {} n {} m {} x {} v {}'.format(h, n, m, x, v))
	print(d)
for i in range(3 * n):
	x += 1
	v += d[i % n]
	if DBG:
		print('i {} x {} v {}'.format(i, x, v))
	if v <= 0:
		print(x)
		break


s1 = list(map(int, input().split()))
s = list(map(int, input().split()))
(h, n) = (s1[0], s1[1])
hp = h
time = 0
mins = 0
sums = 0
for i in range(n):
	sums += s[i]
	mins = min(mins, sums)
while time != n:
	hp = hp + s[time]
	time += 1
	if hp <= 0:
		break
if hp <= 0:
	print(time)
else:
	t = sum(s)
	if t >= 0:
		print(-1)
	else:
		hp1 = h + mins
		cycle = hp1 // abs(t)
		time = n * (hp1 // abs(t))
		timemod = 0
		hp = h - abs(t) * cycle
		while hp > 0:
			hp += s[timemod]
			timemod = (timemod + 1) % n
			time += 1
		print(time)


INF = 10 ** 13
(h, n) = map(int, input().split())
a = list(map(int, input().split()))
b = a[:]
for i in range(1, n):
	b[i] += b[i - 1]
low = min(b)
tot = b[-1]
if h + low <= 0:
	lo = 0
else:
	(lo, hi) = (0, INF)
	while lo < hi:
		mid = (lo + hi) // 2
		cur = h + mid * tot + low
		if cur <= 0:
			hi = mid
		else:
			lo = mid + 1
if lo == INF:
	print(-1)
else:
	steps = lo * n
	cur = h + lo * tot
	for i in range(n):
		cur += a[i]
		steps += 1
		if cur <= 0:
			break
	print(steps)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict as dd, deque as dq
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(H, N) = getInts()
	D = getInts()
	(P, curr) = ([0], 0)
	ops = []
	h.heapify(ops)
	for d in D:
		curr += d
		P += [curr]
	div = -P[-1]
	for (i, p) in enumerate(P):
		if p < 0:
			R = 0
			if H + p > 0:
				if div > 0:
					R = math.ceil((H + p) / div)
					h.heappush(ops, (R, i))
			else:
				return i
	if not ops:
		return -1
	(R, i) = h.heappop(ops)
	return R * N + i
print(solve())


import math
(H, n) = [int(s) for s in input().split()]
changes = [int(s) for s in input().split()]
total = sum(changes)
if total >= 0:
	died = -1
	for (t, change) in enumerate(changes):
		H += change
		if H <= 0:
			died = t + 1
			break
	print(died)
else:
	cumulative_changes = [changes[0]]
	for i in range(1, n):
		cumulative_changes.append(cumulative_changes[-1] + changes[i])
	round = []
	for (t, change) in enumerate(cumulative_changes):
		if H + change <= 0:
			round.append(t + 1)
		else:
			turn = math.ceil((H + change) / -total)
			round.append(turn * n + t + 1)
	print(min(round))


import math
(H, n) = map(int, input().split())
a = list(map(int, input().split()))
pref = [0]
mini = 99999999999
for i in range(n):
	cur = pref[-1] + a[i]
	pref.append(cur)
	if -cur >= H:
		print(i + 1)
		exit()
if pref[-1] >= 0:
	print(-1)
	exit()
ans = 99999999999999999999
for i in range(n + 1):
	ans = min(ans, math.ceil((H + pref[i]) / -pref[-1]) * n + i)
print(ans)


(H, n) = map(int, input().split())
m = 0
a = 0
d = list(map(int, input().split()))
a = 0
for i in range(n):
	a += d[i]
	if a < m:
		m = a
if a >= 0 and H + m > 0:
	print(-1)
	exit()
x = 0
if a >= 0:
	x = 0
else:
	x = max(0, (H + m) // -a - 1)
H = H + a * x
i = 0
while H > 0:
	H += d[i % n]
	i += 1
print(x * n + i)


import itertools
(h, n) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
arr = list(map(lambda x: -x, arr))
s = sum(arr)
tmp = h
ans = 0
for i in arr:
	if tmp <= 0:
		print(ans)
		exit(0)
	tmp -= i
	ans += 1
if tmp <= 0:
	print(ans)
	exit(0)
ans = 0
if s <= 0:
	print(-1)
	exit(0)
running_max = 0
curr = 0
for num in arr:
	curr += num
	if curr > running_max:
		running_max = curr
iterations = h // s
mod = h % s
to_backup = running_max // s
ans = (iterations - to_backup) * n
mod += to_backup * s
for p in itertools.cycle(arr):
	if mod <= 0:
		break
	mod -= p
	ans += 1
print(ans)


from collections import Counter, defaultdict, deque
import itertools

def check_h(h, s):
	for i in range(len(s)):
		if h + s[i] <= 0:
			return i + 1
	return -1
(h, n) = map(int, input().split())
d = list(map(int, input().split()))
ans = -1
s = []
for i in range(n):
	s.append((s[-1] if s else 0) + d[i % n])
ans = check_h(h, s)
if ans != -1:
	print(ans)
elif s[-1] >= 0:
	print(-1)
else:
	ans = float('inf')
	for i in range(n):
		t = s[i]
		k = (h + t) // -s[-1]
		if (h + t) % -s[-1] != 0:
			k += 1
		ans = min(k * n + i + 1, ans)
	print(ans)


import math

def min_info(arr):
	ans = (0, arr[0])
	for i in range(1, len(arr)):
		if arr[i] < ans[1]:
			ans = (i, arr[i])
	return ans
(H, n) = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
cumulative = [d[0]]
for i in range(1, n):
	cumulative.append(cumulative[i - 1] + d[i])
first_round_min = min_info(cumulative)
if first_round_min[1] <= -H:
	i = 0
	while -cumulative[i] < H:
		i += 1
	print(i + 1)
else:
	cpr = cumulative[n - 1]
	if first_round_min[1] < H and cpr >= 0:
		print(-1)
	else:
		min_rounds_required = math.ceil((H + first_round_min[1]) / -cpr)
		min_dmg_last_round = H + cpr * min_rounds_required
		i = 0
		while -cumulative[i] < min_dmg_last_round:
			i += 1
		print(n * min_rounds_required + i + 1)


(h, n) = map(int, input().split())
a = list(map(int, input().split()))
s = 0
m = 0
for i in range(n):
	s += a[i]
	if s < m:
		m = s
if s >= 0 and h + m > 0:
	print(-1)
elif h + m <= 0:
	i = 0
	t = 0
	while h > 0:
		h += a[i % n]
		i += 1
		t += 1
	print(t)
else:
	x = (h + m) // abs(s)
	h += x * s
	t = x * n
	i = 0
	while h > 0:
		h += a[i % n]
		i += 1
		t += 1
	print(t)


(H, n) = map(int, input().split())
from math import ceil
d = list(map(int, input().split(' ')))
prefs = [0 for i in range(n)]
prefs[0] = d[0]
for k in range(1, n):
	prefs[k] = prefs[k - 1] + d[k]
t = 0
if min(prefs) + H > 0:
	if prefs[-1] >= 0:
		print(-1)
	else:
		t += n * ceil((-min(prefs) - H) / prefs[-1])
		H += prefs[-1] * ceil((-min(prefs) - H) / prefs[-1])
		while prefs[t % n] + H > 0:
			t += 1
		print(t + 1)
else:
	while H + prefs[t] > 0:
		t += 1
	print(t + 1)


INF = 100000000
t = 1
for test in range(t):
	(H, n) = list(map(int, input().split()))
	d = list(list(map(int, input().split())))
	pre = [0 for i in range(n + 1)]
	minVal = pre[0]
	minInd = 0
	for i in range(n):
		pre[i + 1] = pre[i] + d[i]
		if pre[i + 1] < minVal:
			minInd = i + 1
			minVal = pre[i + 1]
	h = H
	ans = 0
	for i in d:
		ans += 1
		h += i
		if h <= 0:
			print(ans)
			return
	if pre[-1] >= 0:
		print(-1)
	else:
		h = H
		h += minVal
		tmp = (h - pre[-1] - 1) // -pre[-1]
		ans = tmp * n
		h = H
		h += pre[-1] * tmp
		for i in d:
			ans += 1
			h += i
			if h <= 0:
				print(ans)
				break


(H, n) = (int(t) for t in input().split(' '))
d = [int(t) for t in input().split(' ')]
hp_diff = sum(d)
current_hp = 0
rip_hp_max = 0
for di in d:
	current_hp += di
	rip_hp_max = max(rip_hp_max, -current_hp)
if hp_diff < 0 and rip_hp_max < H:
	required_full_rounds = (H - rip_hp_max) // -hp_diff
else:
	required_full_rounds = 0
hp_after_full_rounds = H + required_full_rounds * hp_diff
current_hp = hp_after_full_rounds
for i in range(2 * n):
	current_hp += d[i % n]
	if current_hp <= 0:
		print(i + 1 + required_full_rounds * n)
		exit()
print(-1)


(H, n) = map(int, input().split())
A = list(map(int, input().split()))
pref = A
mn = 2e+18
for i in range(1, n):
	pref[i] = pref[i] + pref[i - 1]
for i in range(n):
	mn = min(mn, pref[i])
if H + mn > 0 and pref[n - 1] >= 0:
	print(-1)
	exit(0)
(kir, kan) = (0, 3e+18)
kir = int(kir)
kan = int(kan)
if H + mn <= 0:
	kir = 0
else:
	while kir < kan:
		mid = (kir + kan) // 2
		if pref[n - 1] * mid + H + mn > 0:
			kir = mid + 1
		else:
			kan = mid
hit = int(kir * pref[n - 1])
for i in range(len(A)):
	if hit + H + pref[i] <= 0:
		print(int(kir * n + i + 1))
		exit(0)


(H, n) = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))
minposses = []
minever = 0
minrn = 0
for i in range(n):
	minrn += arr[i]
	if minrn < minever:
		minposses.append([-1 * minrn, i + 1])
		minever = minrn
minrn = -1 * minrn
minever = -1 * minever
ans = 0
if minever < H and minrn <= 0:
	print(-1)
elif minever >= H:
	for i in minposses:
		if i[0] >= H:
			print(i[1])
			break
else:
	H -= minever
	ans = H // minrn * n
	if H % minrn == 0:
		mod = minever
		print(ans + minposses[-1][1])
	else:
		ans += n
		mod = minever - (minrn - H % minrn)
		for i in minposses:
			if i[0] >= mod and mod != 0:
				print(ans + i[1])
				break


(h, n) = map(int, input().split())
d = list(map(int, input().split()))
s = 0
sd = 0
for i in range(n):
	s += d[i]
	sd = min(s, sd)
if s >= 0 and h + sd > 0:
	print(-1)
else:
	h_ = h + sd
	if h_ <= 0:
		i = 0
		c = 0
		while h > 0:
			if i == n:
				i = 0
			h += d[i]
			i += 1
			c += 1
		print(c)
	else:
		c = -int(h_ / s)
		h += c * s
		c *= n
		i = 0
		while h > 0:
			if i == n:
				i = 0
			h += d[i]
			i += 1
			c += 1
		print(c)


(H, n) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr1 = []
mostmin = 10 ** 9
val = 0
mostminindex = -1
for i in range(n):
	val += arr[i]
	arr1.append(val)
	if mostmin > val:
		mostmin = val
		mostminindex = i
if mostmin >= 0:
	print(-1)
elif abs(mostmin) < H and val >= 0:
	print(-1)
else:
	turns = -1
	if H + mostmin <= 0:
		turns = 0
	elif val != 0:
		turns = (H - abs(mostmin)) // abs(val)
	else:
		turns = 0
	H -= abs(val) * turns
	minutes = n * turns
	for i in range(n):
		if H + arr1[i] <= 0:
			print(minutes + 1)
			return
		else:
			minutes += 1
	H -= abs(val)
	for i in range(n):
		if arr1[i] + H <= 0:
			print(minutes + 1)
			return
		else:
			minutes += 1
	print(-1)


import math
(h, n) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
mn = 0
sm = 0
counter = 0
done = False
for i in l:
	counter += 1
	sm += i
	mn = min(mn, sm)
	if h + mn <= 0 and done == False:
		print(counter)
		done = True
if sm >= 0:
	if done == False:
		print(-1)
else:
	nh = h + mn
	it = nh // -sm
	if nh % -sm:
		it += 1
	ans = it * n
	h = h + it * sm
	for i in range(n):
		h = h + l[i]
		ans += 1
		if h <= 0 and done == False:
			print(ans)
			break


(h, n) = map(int, input().split())
D = list(map(int, input().split()))
from itertools import accumulate
C = [0] + D
C = list(accumulate(C))
import math
a = C[-1]
ans = 10 ** 35
if a > 0:
	for i in range(n + 1):
		b = C[i]
		if h + b <= 0:
			ans = min(ans, i)
elif a == 0:
	for i in range(n + 1):
		b = C[i]
		if h + b <= 0:
			ans = min(ans, i)
else:
	for i in range(n + 1):
		b = C[i]
		if -h - b <= 0:
			q = (h + b + -a - 1) // -a
			ans = min(ans, q * n + i)
		else:
			q = 0
		ans = min(ans, q * n + i)
if ans == 10 ** 35:
	print(-1)
else:
	print(ans)


from itertools import accumulate
import math
(H, n) = map(int, input().split())
d = list(map(int, input().split()))
acc = list(accumulate(d))
per_round = acc[-1]
m = min(acc)
if m >= 0:
	print(-1)
	return
target = -m
if H <= target:
	rounds = 0
elif per_round >= 0:
	print(-1)
	return
else:
	rounds = math.ceil((H - target) / -per_round)
health = H - rounds * -per_round
for (i, diff) in enumerate(acc):
	cur = health + diff
	if cur <= 0:
		break
minutes = rounds * n + i + 1
print(minutes)


(h, n) = list(map(int, input().split()))
fo = [int(x) for x in input().split()]
ac = [0] * n
miac = [0] * n
for i in range(n):
	ac[i] = ac[i - 1] + fo[i]
	miac[i] = min(ac[i], miac[i - 1])
m = min(ac)
if h + miac[-1] > 0 and ac[-1] >= 0:
	print(-1)
elif h + miac[-1] <= 0:
	(hi, lo) = (n - 1, 0)
	while hi > lo:
		mid = (hi + lo) // 2
		if miac[mid] + h > 0:
			lo = mid + 1
		else:
			hi = mid
	print(hi + 1)
else:
	bajo = (h + miac[-1] - 1) // -ac[-1] + 1
	h += bajo * ac[-1]
	(hi, lo) = (n - 1, 0)
	while hi > lo:
		mid = (hi + lo) // 2
		if miac[mid] + h > 0:
			lo = mid + 1
		else:
			hi = mid
	print(hi + 1 + bajo * n)


(H, n) = list(map(int, input().split()))
d = list(map(int, input().split()))
X = H + 0
flag = True
for i in range(len(d)):
	X += d[i]
	if X <= 0:
		print(i + 1)
		flag = False
		break
j = 0
if flag:
	Y = sum(d)
	z = 0
	maxZ = 0
	for i in range(n):
		if d[i] < 0:
			z += d[i]
		else:
			if maxZ > z:
				maxZ = z
			z += d[i]
	if Y >= 0:
		print(-1)
	else:
		j += n * ((H + maxZ) // abs(Y))
		H += Y * ((H + maxZ) // abs(Y))
		while H > 0:
			H += d[j % n]
			j += 1
		print(j)


from math import ceil
(h, n) = map(int, input().split())
d = list(map(int, input().split()))
cm = [0] * n
cm[0] = d[0]
mx = cm[0]
for i in range(1, n):
	cm[i] = cm[i - 1] + d[i]
	mx = min(cm[i], mx)
if mx * -1 < h and cm[-1] >= 0:
	print(-1)
else:
	ans = 0
	if mx * -1 >= h:
		for i in range(n):
			h += d[i]
			ans += 1
			if h <= 0:
				break
		print(ans)
		exit()
	if mx * -1 < h:
		ans += n * ceil((h + mx) / abs(cm[-1]))
	h = h + ans // n * cm[-1]
	for i in range(n):
		h += d[i]
		ans += 1
		if h <= 0:
			break
	print(ans)


import math
(h, n) = map(int, input().split())
li = list(map(int, input().split()))
li1 = []
for i in range(1, n):
	li[i] += li[i - 1]
p = li[-1]
for i in range(n):
	if li[i] + h <= 0:
		print(i + 1)
		break
else:
	if p >= 0:
		print('-1')
	else:
		for i in range(n):
			h1 = h + li[i]
			a = math.ceil(h1 / abs(p))
			li1.append(a)
		a = min(li1)
		i = li1.index(a)
		print(a * n + i + 1)


(H, n) = map(int, input().split())
sum = 0
time = 0
minsum = int(1e+56)
hp = H
a = input().split()
for i in range(0, len(a)):
	a[i] = int(a[i])
for x in a:
	sum += x
	minsum = min(minsum, sum)
hpp = H
for x in a:
	hpp += x
	time += 1
	if hpp <= 0:
		print(str(time))
		exit(0)
if sum >= 0:
	print('-1')
	exit(0)
sum = -sum
minsum = -minsum
le = 1
r = int(1000000000000.0)
ans = 1
while le <= r:
	c = (le + r) // 2
	if H - sum * c < minsum:
		r = c - 1
	else:
		ans = c
		le = c + 1
time = ans * n
hp = H - sum * ans
while True:
	for x in a:
		hp += x
		time += 1
		if hp <= 0:
			print(time)
			exit(0)


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
(H, n) = listIn()
d = listIn()
s = sum(d)
arr = [0] * n
arr[0] = d[0]
sh = H
for i in range(1, n):
	arr[i] = arr[i - 1] + d[i]
m = abs(min(arr))
for i in range(n):
	sh += d[i]
	if sh <= 0:
		print(i + 1)
		exit(0)
if H - m > 0 and s >= 0:
	print(-1)
else:
	rem = H
	ans = 0
	if rem > m:
		rem -= m
		c = rem / abs(s)
		c1 = int(c)
		if c == c1:
			c = c1
		else:
			c = c1 + 1
		ans += c * n
		H += c * s
	ss = H
	for i in range(1, n + 1):
		ss = ss + d[i - 1]
		if ss <= 0:
			ans += i
			break
	if ans % n == 0:
		for i in range(n - 1, -1, -1):
			if d[i] == 0:
				ans -= 1
			else:
				break
	print(ans)


from sys import exit
from itertools import accumulate
(H, n) = map(int, input().split())
L = map(int, input().split())
LA = list(accumulate(L))
for (i, v) in enumerate(LA, 1):
	if H + v <= 0:
		print(i)
		exit()
if LA[-1] >= 0:
	print(-1)
	exit()
loop = LA[-1]
print(min([-(-(H + LA[i - 1]) // -loop) * n + i for i in range(1, n + 1)]))


def solve(h, n, d):
	sm = sum(d)
	per = 0
	cs = 0
	nad = 0
	for i in d:
		nad += 1
		cs += i
		per = min(per, cs)
		if h + cs <= 0:
			return nad
	if sm >= 0:
		return -1
	cnt = (h + per) // -sm * n
	h += cnt * sm // n
	while 1:
		for i in range(n):
			cnt += 1
			h += d[i]
			if h <= 0:
				return cnt
	return 'fkgjsiofghsefjkgls'
(h, n) = map(int, input().split())
d = list(map(int, input().split()))
print(solve(h, n, d))


import sys
input = sys.stdin.readline
(H, n) = map(int, input().split())
D = list(map(int, input().split()))
from itertools import accumulate
ONETURN = list(accumulate(D))
MIN = min(ONETURN)
ONE = ONETURN[-1]
if ONE >= 0:
	if H + MIN > 0:
		print(-1)
		sys.exit()
	DAMAGED = [H + o for o in ONETURN]
	for i in range(n):
		if DAMAGED[i] <= 0:
			print(i + 1)
			sys.exit()
ANS = 0
R = max(0, (H + MIN) // -ONE)
ANS += R * n
H += R * ONE
while H + MIN > 0:
	H += ONE
	ANS += n
DAMAGED = [H + o for o in ONETURN]
for i in range(n):
	if DAMAGED[i] <= 0:
		print(ANS + i + 1)
		break


from itertools import accumulate
(H, n) = map(int, input().split())
D = list(map(int, input().split()))
accD = list(accumulate(D))
d = sum(D)
m = min(accD)
ans = 0
now = H
if H + m <= 0:
	for i in range(n):
		ans += 1
		now += D[i]
		if now <= 0:
			break
elif d >= 0:
	ans = -1
else:
	ans = (H + m) // -d * n
	now = H + (H + m) // -d * d
	while now > 0:
		for i in range(n):
			ans += 1
			now += D[i]
			if now <= 0:
				break
print(ans)


[H, n] = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
H_old = H
mH = H
for i in range(n):
	H += d[i]
	mH = min(mH, H)
	if H <= 0:
		print(i + 1)
		break
else:
	if H_old <= H:
		print(-1)
	else:
		df = H_old - H
		mD = H_old - mH
		rnds = (mH + df - 1) // df
		H = H_old - rnds * df
		for i in range(n):
			H += d[i]
			if H <= 0:
				print(rnds * n + i + 1)
				break


(h, n) = map(int, input().split())
D = list(map(int, input().split()))
C = [0]
for d in D:
	C.append(C[-1] + d)
mi = min(C)
s = C[-1]
dmg = -s
if s >= 0 and h + mi > 0:
	print(-1)
	exit()
if h + mi > 0:
	t = (h + mi + dmg - 1) // dmg if dmg > 0 else 0
	ans = t * n
	h -= t * dmg
else:
	ans = 0
ans += [i for (i, c) in enumerate(C) if h + c <= 0][0]
print(ans)


(H, n) = map(int, input().split())
d = list(map(int, input().split()))
(diff, max_damage) = (0, 0)
for di in d:
	diff += di
	max_damage = max(max_damage, -diff)
if max_damage >= H:
	for i in range(n):
		H += d[i]
		if H <= 0:
			print(i + 1)
			exit()
D = sum(d)
if D >= 0:
	print(-1)
	exit()
D *= -1
ans = (H - max_damage + D - 1) // D * n
H -= (H - max_damage + D - 1) // D * D
for di in d:
	H += di
	ans += 1
	if H <= 0:
		print(ans)
		exit()


(H, n) = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
u = 0
alpha = 0
mini = a[0]
for i in range(n):
	u += a[i]
	mini = min(mini, u)
	if H + u <= 0:
		alpha = 1
if alpha == 0 and s >= 0:
	print('-1')
else:
	t = H
	ans = 0
	if abs(mini) < H:
		if abs(s) != 0:
			t = t // abs(s)
		else:
			t = 0
		if t >= 0:
			ans = t * n
			H = H - abs(s) * t
			bal = 1
			if s != 0:
				bal = abs(mini) // abs(s)
				H += bal * abs(s)
				ans -= bal * n
	i = 0
	while 1:
		if i == n:
			i = 0
			continue
		if H <= 0:
			break
		H += a[i]
		ans += 1
		i += 1
	print(ans)


(h, n) = map(int, input().split())
d = list(map(int, input().split()))
minn = h
cnt = 0
for i in range(n):
	h += d[i]
	cnt += 1
	minn = min(minn, h)
	if h <= 0:
		exit(print(cnt))
if sum(d) >= 0:
	exit(print(-1))
tmp = max(0, minn // -sum(d) - 2)
h += tmp * sum(d)
cnt += n * tmp
for i in range(100000000):
	cnt += 1
	h += d[i % n]
	if h <= 0:
		exit(print(cnt))


(h, n) = map(int, input().split())
D = [int(x) for x in input().split()]

def eval1(start):
	H = [start]
	for d in D:
		H.append(H[-1] + d)
	return H

def first_npos(A):
	for i in range(len(A)):
		if A[i] <= 0:
			return i
H = eval1(h)
mn = min(H)
drift = H[-1] - H[0]
if drift >= 0 and mn > 0:
	print(-1)
elif drift >= 0:
	H = eval1(h)
	i = first_npos(H)
	if i == None:
		i = -1
	print(i)
else:
	l = -1
	r = 10 ** 13
	while r - l > 1:
		m = (r + l) // 2
		if mn + drift * m <= 0:
			r = m
		else:
			l = m
	start = h + r * drift
	H = eval1(start)
	i = first_npos(H)
	print(n * r + i)


from sys import stdin
(H, n) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
k = H
d = {}
pre = 0
cond = False
for i in range(n):
	k += arr[i]
	pre += arr[i]
	if pre in d:
		d[pre].append(i + 1)
	else:
		d[pre] = [i + 1]
	if k <= 0:
		ans = i + 1
		cond = True
		break
	else:
		pass
if cond == True:
	print(ans)
else:
	s = sum(arr)
	if s < 0:
		a = min(list(d.keys()))
		m = (H + a) // abs(s)
		H += s * m
		ans = n * m
		while H > 0:
			l = list(filter(lambda x: x + H <= 0, d.keys()))
			if len(l) > 0:
				case = []
				for ele in l:
					case.extend(d[ele])
				ans += min(case)
				print(ans)
				break
			else:
				H += s
				ans += n
	else:
		print(-1)


(health, n) = map(int, input().split())
arr = list(map(int, input().split()))
arr_sum = 0
for x in arr:
	arr_sum += x
best_time = -1
for i in range(n):
	if i > 0:
		arr[i] += arr[i - 1]
	k = -1
	if health + arr[i] <= 0:
		k = 0
	if k < 0 and arr_sum < 0:
		k = (health + arr[i] - arr_sum - 1) // -arr_sum
	if k >= 0:
		temp = n * k + i + 1
		if best_time == -1 or temp < best_time:
			best_time = temp
print(best_time)


inp = input()
(H, n) = list(map(int, inp.split()))
inp = input()
d = list(map(int, inp.split()))

def ans(H, n, d):
	dpr = 0
	gap = 0
	for i in range(n):
		H += d[i]
		dpr -= d[i]
		gap = max(gap, dpr)
		if H <= 0:
			return i + 1
	if dpr <= 0:
		return -1
	r = (H - gap) // dpr - 1
	H -= r * dpr
	res = r * n
	for i in range(n * n):
		H += d[i % n]
		res += 1
		if H <= 0:
			return res + n
print(ans(H, n, d))


from math import *
(h, n) = map(int, input().split())
d = list(map(int, input().split()))
s = 0
sp = list(range(n))
ok = 0
for i in range(n):
	s += d[i]
	if s + h <= 0:
		print(i + 1)
		ok = 1
		break
	sp[i] = s
if not ok:
	if s >= 0:
		print(-1)
	else:
		m = n * ceil(h / -s)
		for i in range(n):
			if sp[i] < 0:
				m = min(m, i + 1 + n * ceil((h + sp[i]) / -s))
		print(m)


from math import ceil
(h, n) = map(int, input().split())
(a, s, mi, ans) = (list(map(int, input().split())), 0, [float('inf'), 0], 0)
for i in range(n):
	s += a[i]
	if s < mi[0]:
		mi = [s, i]
	if -s >= h:
		exit(print(i + 1))
if mi[0] > -1 or sum(a) > -1:
	exit(print(-1))
ans += ceil((h + mi[0]) / -sum(a)) * n
if (h + mi[0]) % -sum(a) == 0:
	ans += mi[1] + 1
else:
	diff = -sum(a) - (h + mi[0]) % -sum(a)
	(tem, flag) = (n, 1)
	for i in range(mi[1], -1, -1):
		diff += a[i]
		if diff < 0 and flag:
			(tem, flag) = (i + 1, 0)
		elif diff == 0 and flag:
			(tem, flag) = (i, 0)
		if diff >= 0:
			flag = 1
	ans += tem
print(ans)


from itertools import accumulate
(H, n) = map(int, input().split())
arr = list(map(int, input().split()))
sum_arr = sum(arr)
max_diff = min(accumulate(arr))
if sum_arr >= 0:
	total_days = 0
else:
	value = max(H // abs(sum_arr) - abs(max_diff) // abs(sum(arr)), 0)
	if value == 0:
		total_days = 0
	else:
		total_days = value * n
		H = H - value * abs(sum(arr))
if H <= 0:
	print(total_days)
else:
	while H > 0:
		for item in arr:
			if H + item <= 0:
				print(total_days + 1)
				break
			else:
				H = H + item
				total_days += 1
		else:
			if sum_arr >= 0:
				print(-1)
				break
			continue
		break


(h, n) = map(int, input().split())
d = list(map(int, input().split()))
sm = 0
mnn = 0
for i in range(n):
	sm += d[i]
	mnn = min(mnn, sm)
	if sm + h <= 0:
		print(i + 1)
		exit(0)
if sm >= 0:
	print(-1)
	exit(0)
mnn *= -1
sm *= -1
ans = (h - mnn) // sm * n
mnn += (h - mnn) % sm
cur = 0
while mnn > 0:
	mnn += d[cur]
	ans += 1
	cur += 1
	cur %= n
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST():
	return list(map(int, input().split()))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
(H, N) = MAP()
D = LIST()
mx = -INF
sm = 0
for i in range(N):
	sm -= D[i]
	mx = max(mx, sm)
	if mx >= H:
		print(i + 1)
		exit()
if sm <= 0:
	print(-1)
	exit()
X = ceil(H - mx, sm)
H -= X * sm
ans = X * N
for i in range(N):
	H += D[i]
	ans += 1
	if H <= 0:
		print(ans)
		break


if True:
	(H, n) = map(int, input().split())
	D = [int(a) for a in input().split()]
else:
	D = [-100, -200, -300, 125, 77, -4]
	H = 1000
	n = len(D)
s = -sum(D)
mi = 0
h = 0
for i in range(n):
	h += D[i]
	if H + h <= 0:
		print(i + 1)
		break
	if h < mi:
		mi = h
else:
	if s <= 0:
		print(-1)
	else:
		t = -(-(H + mi) // s)
		h = H - s * t
		for i in range(n):
			h += D[i]
			if h <= 0:
				print(i + 1 + n * t)
				break
		else:
			print('ERROR')


(h, n) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
summa = sum(a)
prev = 0
minim = 10 ** 90
for item in a:
	prev += item
	minim = min(minim, prev)
if summa < 0:
	counter = (h + minim) % abs(summa)
	prev_answer = (h + minim) // abs(summa)
	i = 1
	counter -= minim
	if prev_answer <= 0:
		counter = h
		prev_answer = 0
	while 1:
		i = 1
		for item in a:
			counter += item
			if counter <= 0:
				print(prev_answer * n + i)
				exit()
			i += 1
		prev_answer += 1
elif h + minim <= 0:
	i = 1
	for item in a:
		h += item
		if h <= 0:
			print(i)
			break
		i += 1
else:
	print(-1)


(h, n) = map(int, input().split())
l1 = list(map(int, input().split()))
x = sum(l1)
y = h
t = 0
m = 0
f = 0
for item in l1:
	f += item
	m = min(m, f)
if x < 0:
	t = t + max(h + m, 0) // abs(x) * n
	h = h + t // n * x
	while h > -1 * m:
		h += x
		t += n
	for item in l1:
		h += item
		t += 1
		if h <= 0:
			break
	print(t)
else:
	for item in l1:
		h += item
		t += 1
		if h <= 0:
			break
	if h > 0:
		print(-1)
	else:
		print(t)


(H, n) = map(int, input().split())
d = list(map(int, input().split()))
res = 0
hp_min_level_within_round = 0
hp_level_within_round = 0
for di in d:
	res += 1
	hp_level_within_round += di
	if hp_level_within_round < hp_min_level_within_round:
		hp_min_level_within_round = hp_level_within_round
	if H + hp_level_within_round <= 0:
		print(res)
		exit()
hp_gain_per_round = hp_level_within_round
if hp_gain_per_round >= 0:
	print(-1)
	exit()
full_rounds = (H + hp_min_level_within_round - 1) // -hp_gain_per_round + 1
res = full_rounds * n
current_hp_gain = full_rounds * hp_gain_per_round
for di in d:
	res += 1
	current_hp_gain += di
	if H + current_hp_gain <= 0:
		print(res)
		exit()


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return list(map(int, minp().split()))
(H, n) = mints()
d = list(mints())
s = [0] * (n + 1)
for i in range(n):
	s[i + 1] = s[i] + d[i]
for i in range(n + 1):
	if s[i] + H <= 0:
		print(i)
		return
if s[n] >= 0:
	print(-1)
else:
	l = -1
	r = H // -s[n] + 2
	while r - l > 1:
		c = (l + r) // 2
		h = -c * s[n] - H
		z = -1
		for i in range(n + 1):
			if s[i] <= h:
				z = i
				break
		if z == -1:
			l = c
		else:
			r = c
	h = -r * s[n] - H
	z = -1
	for i in range(n + 1):
		if s[i] <= h:
			print(r * n + i)
			break


import math
(h, n) = list(map(int, input().split()))
l = list(map(int, input().split()))
pr = [0] * n
pr[0] = l[0]
for i in range(1, n):
	pr[i] = pr[i - 1] + l[i]
cnt = []
if pr[-1] >= 0 and abs(min(pr)) < h:
	print(-1)
	exit()
else:
	for i in range(n):
		if abs(pr[i]) >= h:
			cnt.append(i + 1)
		else:
			if pr[i] >= 0:
				continue
			cnt.append(math.ceil((h + pr[i]) / abs(pr[-1])) * n + i + 1)
print(min(cnt))


(H, n) = map(int, input().split())
arr = [int(i) for i in input().split()]
tot = sum(arr)
ans = 0
curr = H
for i in arr:
	curr += i
	ans += 1
	if curr <= 0:
		print(ans)
		exit(0)
if tot >= 0:
	print(-1)
	exit(0)
(l, r) = (0, int(1000000000000.0 + 5))
while l < r:
	mid = (l + r) // 2
	good = False
	curr = H + tot * mid
	if curr <= 0:
		good = True
	for i in arr:
		curr += i
		if curr <= 0:
			good = True
			break
	if good:
		r = mid
	else:
		l = mid + 1
ans = r * n
curr = H + tot * r
if curr <= 0:
	print(ans)
	exit(0)
for i in arr:
	curr += i
	ans += 1
	if curr <= 0:
		print(ans)
		exit(0)


(h, n) = map(int, input().split())
d = [i for i in map(int, input().split())]
ans = -1
if h > 0:
	hs = h
	ar = []
	su = 0
	for i in range(n):
		h += d[i]
		su += d[i]
		ar.append(su)
		if h <= 0:
			ans = i + 1
			break
	ansar = []
	if len(ar) and ar[-1] < 0 and (ans == -1):
		ab = -1 * ar[-1]
		for (ind, val) in enumerate(ar):
			tm = ind + 1
			h = hs + val
			tm += n * ((h + ab - 1) // ab)
			ansar.append(tm)
		ans = min(ansar)
print(ans)


(h, n) = [int(i) for i in input().split()]
dam = [int(i) for i in input().split()]
mi = float('inf')
su = 0
fake = h
flag = False
minu = 0
for v in dam:
	su += v
	mi = min(mi, su)
	fake += v
	if fake <= 0 and (not flag):
		flag = True
		minu += 1
	elif not flag:
		minu += 1
if flag:
	print(minu)
elif su >= 0:
	print(-1)
else:
	full = abs(int((h + mi) / su))
	h += full * su
	res = full * n
	i = 0
	while h > 0:
		h += dam[i % n]
		res += 1
		i += 1
	print(res)


from math import ceil
(H, N) = map(int, input().split())
ls = list(map(int, input().split()))
orig = H
count = 0
Sum = 0
for i in ls:
	Sum += i
	count = min(count, Sum)
if Sum >= 0:
	if orig + count <= 0:
		x = 0
	else:
		print(-1)
		quit()
else:
	H = count + H
	if H <= 0:
		x = 0
	else:
		x = ceil(-H / Sum)
H = orig + Sum * x
x = x * N
for i in ls:
	H += i
	x += 1
	if H <= 0:
		print(x)
		quit()


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, sin, cos, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import random
import sys
sys.setrecursionlimit(1000000000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def euclidean_distance(y1, x1, y2, x2):
	return sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2)

def manhattan_distance(y1, x1, y2, x2):
	return abs(y1 - y2) + abs(x1 - x2)

def make_random_list(n, mini, maxi):
	return [random.randint(mini, maxi) for i in range(n)]

def sim(H, D):
	if H <= 0:
		return (H, 0)
	ans = 0
	for d in D:
		ans += 1
		H += d
		if H <= 0:
			return (H, ans)
	return (H, ans)

def solve(H, N, D):
	(h, num) = sim(H, D)
	if h <= 0:
		return num
	total = sum(D)
	if total >= 0:
		return -1
	mini = INF
	now = 0
	for d in D:
		now += d
		mini = min(mini, now)
	num = max(0, (H - abs(mini)) // abs(total) - 2)
	ans = num * N
	H -= abs(total) * num
	while H > 0:
		(h, num) = sim(H, D)
		ans += num
		H = h
	return ans

def main():
	(H, N) = map(int, input().split())
	D = list(map(int, input().split()))
	print(solve(H, N, D))
main()


(h, n) = map(int, input().split())
arr = list(map(int, input().split()))
k = 0
for i in range(len(arr)):
	k += arr[i]
	if h + k <= 0:
		print(i + 1)
		exit(0)
s = -sum(arr)
if s <= 0:
	print(-1)
	exit(0)
m = float('inf')
e = 0
for i in range(len(arr)):
	e -= arr[i]
	m = min(max(0, h - e + s - 1) // s * n + i + 1, m)
print(m)


import math

def test(k):
	nonlocal sm, mn, h
	return h + k * sm + mn <= 0
(h, n) = map(int, input().split())
a = list(map(int, input().split()))
mn = math.inf
sm = 0
for e in a:
	sm += e
	mn = min(mn, sm)
if mn >= 0:
	print(-1)
	return
l = -1
r = h + 1
while r - l > 1:
	m = (r + l) // 2
	if test(m):
		r = m
	else:
		l = m
h += sm * r
if h <= 0:
	print(n * r)
	return
for i in range(n):
	h += a[i]
	if h <= 0:
		print(r * n + i + 1)
		return
print(-1)


(h, n) = map(int, input().split())
l = list(map(int, input().split()))
pref = [0] * (n + 1)
ans = -1
for i in range(n):
	pref[i + 1] = pref[i] + l[i]
	if h + pref[i + 1] <= 0:
		ans = i + 1
		break
if ans != -1 or pref[n] >= 0:
	print(ans)
else:
	m = min(pref)
	x = abs((h + m) // pref[n])
	ans = n * x
	h += x * pref[n]
	for i in range(10 * n):
		h += l[i % n]
		ans += 1
		if h <= 0:
			print(ans)
			break


import math

def work(n, m):
	len_ = len(m)
	sum_ = sum(m)
	if sum_ >= 0:
		count = 0
		remain = n[0]
		for i in m:
			remain += i
			count += 1
			if remain <= 0:
				return count
		return -1
	maxHurt = 0
	tmp = 0
	for i in m:
		tmp += i
		maxHurt = min(maxHurt, tmp)
	maxHurt *= -1
	tmp = n[0] - maxHurt
	if tmp < 0:
		tmp = 0
	count = math.ceil(tmp / -sum_) * len_
	remain = n[0] + count / len_ * sum_
	for i in m:
		remain += i
		count += 1
		if remain <= 0:
			return count
n = list(map(int, input().split()))
m = list(map(int, input().split()))
print(work(n, m))


def helper(dl, H):
	(min_index, min_value) = (0, 0)
	acc_sum = 0
	kill_index = -1
	kill_flag = True
	for i in range(len(dl)):
		acc_sum += dl[i]
		if kill_flag and acc_sum + H <= 0:
			kill_index = i + 1
			kill_flag = False
		if acc_sum < min_value:
			min_value = acc_sum
			min_index = i
	return (min_value, min_index + 1, kill_index, dl[min_index + 1:] + dl[:min_index + 1])

def solve(H, dl):
	(dH, n, kill_index, dl) = helper(dl, H)
	if H + dH <= 0:
		return kill_index
	H += dH
	round_drop = sum(dl)
	if round_drop >= 0:
		return -1
	(num_round, remainder) = (H // abs(round_drop), H % abs(round_drop))
	remain_round = 0
	while remainder > 0:
		remainder += dl[remain_round]
		remain_round += 1
	return n + num_round * len(dl) + remain_round

def main():
	(H, n) = map(int, input().split())
	dl = list(map(int, input().split()))
	print(solve(H, dl))
main()


def pd(x, dis, minh):
	return dis * (x - 1) + minh <= 0
(h, n) = map(int, input().split())
A = list(map(int, input().split()))
k = h
minh = h
for a in A:
	k += a
	minh = min(minh, k)
if k >= h and minh > 0:
	print(-1)
	exit(0)
if k >= h and minh <= 0:
	oo = h
	for i in range(n):
		oo += A[i]
		if oo <= 0:
			print(i + 1)
			exit(0)
dis = k - h
l = 1
r = 10000000000000000
ki = 0
while l <= r:
	mid = l + r >> 1
	if pd(mid, dis, minh):
		ki = mid
		r = mid - 1
	else:
		l = mid + 1
ki -= 1
time = ki * n
h += dis * ki
for a in A:
	h += a
	time += 1
	if h <= 0:
		print(time)
		exit(0)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
(H, n) = map(int, input().split())
arr = [int(i) for i in input().split()]
tot = sum(arr)
ans = 0
curr = H
for i in arr:
	curr += i
	ans += 1
	if curr <= 0:
		print(ans)
		exit(0)
if tot >= 0:
	print(-1)
	exit(0)
(l, r) = (0, int(1000000000000.0 + 5))
while l < r:
	mid = (l + r) // 2
	good = False
	curr = H + tot * mid
	if curr <= 0:
		good = True
	for i in arr:
		curr += i
		if curr <= 0:
			good = True
			break
	if good:
		r = mid
	else:
		l = mid + 1
ans = r * n
curr = H + tot * r
if curr <= 0:
	print(ans)
	exit(0)
for i in arr:
	curr += i
	ans += 1
	if curr <= 0:
		print(ans)
		exit(0)


[h, n] = list(map(int, input().split()))
d = list(map(int, input().split()))
import sys
count = 0
lost = -sum(d)
total = 0
minimum = 0
for i in d:
	total += i
	minimum = min(total, minimum)
if h + minimum <= 0:
	i = 0
	while h > 0:
		count += 1
		h += d[i]
		i += 1
		i = i % n
	print(count)
	sys.exit(0)
if lost <= 0:
	print(-1)
	sys.exit(0)
rounds = (h + minimum) // lost
h = h - rounds * lost
i = 0
while h > 0:
	count += 1
	h += d[i]
	i += 1
	i = i % n
count += rounds * n
print(count)


(health, length) = [int(number) for number in input().split()]
figth = [int(number) for number in input().split()]
healthCopy = health
lowest = health
done = False

def ceildiv(a, b):
	return -(-a // b)
for i in range(length):
	healthCopy += figth[i]
	if healthCopy < lowest:
		lowest = healthCopy
	if healthCopy <= 0:
		print(i + 1)
		done = True
		break
healthRound = health - healthCopy
if healthRound <= 0:
	if done == False:
		print(-1)
elif done == False:
	time = 0
	healthCopy = health
	maxLoss = health - lowest
	cNumber = health // healthRound
	lNumber = maxLoss // healthRound
	rNumber = cNumber - lNumber
	healthCopy = health - rNumber * healthRound
	time = rNumber * length
	while not done:
		if healthCopy <= maxLoss:
			for i in range(length):
				healthCopy += figth[i]
				if healthCopy <= 0:
					print(time + i + 1)
					done = True
					break
		else:
			time += length
			healthCopy -= healthRound


import math
arr = input()
(H, M) = [int(x) for x in arr.split(' ')]
arr = input()
arr = [int(x) for x in arr.split(' ')]
p_sum = [0] * M
s = 0
for i in range(M):
	s += arr[i]
	p_sum[i] = s
	if abs(s) >= H and s <= 0:
		print(i + 1)
		quit()
if p_sum[-1] >= 0:
	print(-1)
	quit()
rounds = (H - abs(min(p_sum))) / abs(p_sum[-1])
N = math.ceil(rounds)
H = H + p_sum[-1] * N
res = N * M
s = 0
for i in range(M):
	s += arr[i]
	if abs(s) >= H and s <= 0:
		print(res + i + 1)
		quit()


(HP, n) = [int(x) for x in input().split()]
rounds = [int(x) for x in input().split()]
net_change = 0
max_damage = 0
present_damage = 0
minutes_passed = 0

def find_last_minutes(hp_left):
	global rounds, n
	for y in range(0, n):
		if hp_left <= 0:
			return y
		hp_left += rounds[y]
	return n
for x in range(0, n):
	net_change += rounds[x]
	present_damage += rounds[x]
	max_damage = min(max_damage, present_damage)
if HP + max_damage <= 0:
	print(find_last_minutes(HP))
	exit()
if net_change >= 0:
	print(-1)
	exit()
else:
	rounds_used = (HP + max_damage) / -net_change
	rounds_used = int(rounds_used)
	minutes_passed += rounds_used * n
	HP += rounds_used * net_change
	x = 0
	while True:
		if HP <= 0:
			print(int(minutes_passed))
			exit()
		else:
			HP += rounds[x % n]
			minutes_passed += 1
			x += 1


import itertools
import math
(h, n) = map(int, input().split())
d = list(map(int, input().split()))
sd = list(itertools.accumulate(d))
s = sum(d)
hp = h
for i in range(n):
	hp += d[i]
	if hp <= 0:
		print(i + 1)
		exit()
if s >= 0:
	print(-1)
	exit()
ans = 10 ** 100
s *= -1
for i in range(n):
	t = h + sd[i]
	c = math.ceil(t / s) * n
	c += i + 1
	ans = min(ans, c)
print(ans)


import math

def cumuleffects(l):
	current = 0
	output = []
	for item in l:
		current += item
		output.append(current)
	return output

def timeneeded(h, n, results, maxeffect, finaleffect):
	if finaleffect >= 0:
		if h + maxeffect > 0:
			return -1
		else:
			for i in range(len(results)):
				if h + results[i] <= 0:
					return i + 1
	f = -1 * finaleffect
	m = -1 * maxeffect
	r = max(0, math.ceil((h - m) / f))
	h -= r * f
	if h == 0:
		return r * n
	else:
		for i in range(len(results)):
			if h + results[i] <= 0:
				return r * n + i + 1
(h, n) = map(int, input().split())
results = cumuleffects([int(x) for x in input().split()])
maxeffect = min(results)
finaleffect = results[-1]
print(timeneeded(h, n, results, maxeffect, finaleffect))


(H, n) = list(map(int, input().strip().split()))
d = list(map(int, input().strip().split()))
start = 0
max_damage = 0
time_damages = list()
for di in d:
	start -= di
	time_damages.append(start)
	if start > max_damage:
		max_damage = start
round_damage = start
if round_damage <= 0 and max_damage < H:
	print(-1)
else:
	first_round = False
	if max_damage >= H:
		first_round = True
		for (idx, time_damage) in enumerate(time_damages):
			if time_damage >= H:
				print(idx + 1)
				break
	if first_round:
		pass
	else:
		if H - max_damage <= round_damage:
			hg = round_damage
			num_tries = int(hg / round_damage)
			remaining = H - round_damage
		else:
			hg = H - max_damage
			num_tries = int(hg / round_damage)
			prev_round_rem = (H - max_damage) % round_damage
			if prev_round_rem == 0:
				remaining = max_damage
			else:
				remaining = max_damage + prev_round_rem - round_damage
				num_tries += 1
		for (idx, time_damage) in enumerate(time_damages):
			if time_damage >= remaining:
				last_round_time_stamp = idx + 1
				break
		print(num_tries * n + last_round_time_stamp)


(hp, n) = map(int, input().split())
d = input()
d = list(map(int, d.split()))
per = 0
Min = 0
count = 0
q = True
for i in range(n):
	per += d[i]
	if per < Min:
		Min = per
	if hp + per <= 0:
		q = False
		print(i + 1)
		break
if q:
	if per >= 0:
		print(-1)
	else:
		t = (hp + Min) // -per
		if (hp + Min) % -per != 0:
			t += 1
		count = n * t
		hp += per * t
		j = 0
		while hp > 0 and j < n:
			hp += d[j]
			j += 1
		print(count + j)


from sys import stdin
from math import ceil
(h, n) = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
mn = s[0]
mx = s[0]
x = 0
for i in range(n):
	x += s[i]
	mn = min(x, mn)
	mx = max(x, mx)
if x >= 0 and mn * -1 < h:
	print(-1)
	exit(0)
if x >= 0:
	y = 0
else:
	y = max(ceil(-(h + mn) / x), 0)
ans = y * n
h += x * y
for i in range(n):
	if h <= 0:
		break
	h += s[i]
	ans += 1
print(ans)


(h, n) = map(int, input().split())
ar = [[0, 0]]
di = list(map(int, input().split()))
num = 0
for i in range(n):
	num += di[i]
	if num < ar[-1][0]:
		ar += [[num, i + 1]]
if num >= 0 and h + ar[-1][0] > 0:
	print(-1)
elif num >= 0:
	for i in ar:
		if h + i[0] <= 0:
			print(i[1])
			break
else:
	num = -num
	h += ar[-1][0]
	ans = h // num
	if h % num != 0:
		ans += 1
	ans = max(ans, 0)
	h -= ans * num
	h -= ar[-1][0]
	ans *= n
	for i in ar:
		if h + i[0] <= 0:
			print(ans + i[1])
			break


(H, n) = list(map(int, input().split()))
ds = [int(x) for x in input().split()]
h = H
mn = 0
for (i, d) in enumerate(ds):
	h += d
	mn = min(mn, h - H)
	if h <= 0:
		print(i + 1)
		break
else:
	sd = sum(ds)
	if sd >= 0:
		print(-1)
	else:
		sd = -sd
		repeat = (H + mn) // sd
		h = H - repeat * sd
		for (i, d) in enumerate(ds):
			h += d
			if h <= 0:
				print(repeat * n + i + 1)
				break
		else:
			for (i, d) in enumerate(ds):
				h += d
				if h <= 0:
					print(repeat * n + i + 1 + n)
					break


def main():
	(H, n) = map(int, input().split())
	d = list(map(int, input().split()))
	s = [0]
	for x in d:
		s.append(s[-1] + x)
	mn = min(s)
	dif = s[-1]
	t = 0
	if H <= -mn:
		for x in s:
			if H + x <= 0:
				print(t)
				return
			t += 1
	elif dif >= 0:
		print(-1)
		return
	else:
		ts = (H + mn - dif - 1) // -dif
		t += n * ts
		H += dif * ts
		for x in s:
			if H + x <= 0:
				print(t)
				return
			t += 1
main()


(hp, n) = [int(i) for i in input().split()]
damages = [int(i) for i in input().split()]
sums = sum(damages)
minim = 0
current = 0
for v in damages:
	current += v
	if current <= minim:
		minim = current
max_loss = -minim
cnt = 0
if sums >= 0:
	for (i, v) in enumerate(damages):
		cnt += 1
		hp += v
		if hp <= 0:
			print(cnt)
			break
	else:
		print(-1)
		exit()
else:
	total_damage = -sums
	rounds = (hp - max_loss) // total_damage
	if (hp - max_loss) % total_damage == 0:
		rounds -= 1
	if rounds < 0:
		rounds = 0
	hp -= rounds * total_damage
	cnt += n * rounds
	while hp > 0:
		for (i, v) in enumerate(damages):
			cnt += 1
			hp += v
			if hp <= 0:
				break
	print(cnt)


import math
(h, n) = map(int, input().split(' '))
d = list(map(int, input().split(' ')))
round_diff = sum(d)
min_diff = 0
s = 0
for (i, v) in enumerate(d):
	s += v
	min_diff = min(s, min_diff)
round = 0
if round_diff >= 0:
	if h + min_diff > 0:
		print(-1)
		exit(0)
elif h + min_diff > 0:
	round = int(math.ceil((h + min_diff) / -round_diff))
h += round_diff * round
for (i, v) in enumerate(d):
	h += v
	if h <= 0:
		print(round * n + i + 1)
		break


from math import floor
(H, n) = (int(x) for x in input().split())
d = [int(x) for x in input().split()]
sum_d = sum(d)
max_damage_per_round = 0
damage_sofar = 0
for attack in d:
	damage_sofar += attack
	max_damage_per_round = min(max_damage_per_round, damage_sofar)
max_damage_per_round = abs(max_damage_per_round)
answer = 0
for attack in d:
	answer += 1
	H += attack
	if H <= 0:
		print(answer)
		return
if sum_d >= 0:
	print(-1)
	return
if H > max_damage_per_round:
	can_attack_rounds_count = floor((H - max_damage_per_round - 1) / abs(sum_d))
	answer += n * can_attack_rounds_count
	H += sum_d * can_attack_rounds_count
if H <= 0:
	print(answer)
	return
while True:
	for attack in d:
		answer += 1
		H += attack
		if H <= 0:
			print(answer)
			return


from sys import stdin, stdout
(H, n) = stdin.readline().strip().split(' ')
(H, n) = (int(H), int(n))
r = list(map(int, stdin.readline().strip().split(' ')))
maxmin = r[0]
maxminind = 0

def lastroundminutes(hp):
	global r
	for i in range(len(r)):
		if r[i] + hp <= 0:
			return i + 1
for i in range(1, len(r)):
	r[i] = r[i] + r[i - 1]
	if maxmin > r[i]:
		maxmin = r[i]
		maxminind = i
if r[-1] >= 0:
	if H + maxmin <= 0:
		stdout.write(str(lastroundminutes(H)))
	else:
		stdout.write('-1')
elif H + maxmin <= 0:
	stdout.write(str(lastroundminutes(H)))
else:
	H = H + maxmin
	t1 = H // (-1 * r[-1])
	t2 = H % (-1 * r[-1])
	if t2 == 0:
		stdout.write(str(n * t1 + lastroundminutes(-1 * maxmin)))
	else:
		stdout.write(str(n * (t1 + 1) + lastroundminutes(-1 * maxmin - (-1 * r[-1] - t2))))


(k, n) = map(int, input().split())
import math
l = list(map(int, input().split()))
x = sum(l)
c = 0
d = 0
for i in l:
	d += i
	c = min(c, d)
if x >= 0:
	if k + c <= 0:
		time = 0
		i = 0
		while i < n and k > 0:
			k += l[i]
			time += 1
			i += 1
		print(time)
	else:
		print(-1)
elif k + c <= 0:
	time = 0
	i = 0
	while i < n and k > 0:
		k += l[i]
		time += 1
		i += 1
	print(time)
else:
	d = k
	k -= -1 * c
	v = math.ceil(k / (-1 * x))
	time = v * n
	k = k + x * v
	k = -1 * c + k
	i = 0
	while i < n and k > 0:
		time += 1
		k += l[i]
		i += 1
	print(time)


(k, n) = map(int, input().split())
l = [int(i) for i in input().split()]
s = sum(l)
l1 = l[:]
pre = 0
for i in range(n):
	pre += l[i]
	if k + pre <= 0:
		print(i + 1)
		exit()
if s >= 0:
	print(-1)
	exit()
for i in range(1, n):
	l[i] += l[i - 1]
maxim = -min(l)
s = -s
ind = l.index(min(l))
from math import ceil
req = ceil((k - maxim) // s)
i = 0
k = k - req * s
req *= n
i = 0
while 1:
	if k <= 0:
		break
	k += l1[i % n]
	i += 1
	req += 1
print(req)


(h, n) = map(int, input().split())
lst = list(map(int, input().split()))
summa = sum(lst) * -1
res = -1
from sys import exit
for (i, x) in enumerate(lst):
	h += x
	if summa <= 0:
		if h <= 0:
			print(i + 1)
			exit()
	else:
		(mod, div) = (h % summa, h // summa)
		if h <= 0 and i + 1 < res:
			print(i + 1)
			exit()
		if mod > 0:
			div += 1
		if res > i + 1 + div * n:
			res = i + 1 + div * n
		if res == -1:
			res = i + 1 + div * n
print(res)


import math

def f(hp, rd_length, t):
	t_sum = 0
	rd_min = 0
	count = 0
	hp_temp = hp
	for num in t:
		hp_temp += num
		count += 1
		if hp_temp <= 0:
			return count
		t_sum += num
		if t_sum < rd_min:
			rd_min = t_sum
	if t_sum >= 0:
		return -1
	elif rd_min < t_sum:
		total_rounds = math.ceil(-(hp + rd_min) / t_sum)
		hp += total_rounds * t_sum
		count = rd_length * total_rounds
		for num in t:
			hp += num
			count += 1
			if hp <= 0:
				return count
	else:
		total_rounds = math.ceil(-hp / t_sum)
		hp += (total_rounds - 1) * t_sum
		count = rd_length * (total_rounds - 1)
		for num in t:
			hp += num
			count += 1
			if hp <= 0:
				return count
a = input().split()
hp = int(a[0])
rd_length = int(a[1])
b = input().split()
t = list(map(int, b))
print(f(hp, rd_length, t))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
prefix = [0] * k
prefix[0] = arr[0]
mini = arr[0]
for i in range(1, k):
	prefix[i] += prefix[i - 1] + arr[i]
	if prefix[i] < mini:
		mini = prefix[i]
if abs(mini) >= n:
	ans = 0
	for i in range(k):
		n += arr[i]
		ans += 1
		if n <= 0:
			print(ans)
			exit()
elif prefix[k - 1] >= 0 or mini > 0:
	print('-1')
	exit()
else:
	ct = (n - abs(mini)) // abs(prefix[k - 1])
	a = max(ct - 1, 0)
	b = ct
	c = ct + 1
	ans1 = a * k
	j = n + a * prefix[k - 1]
	for i in range(k):
		if j <= 0:
			break
		j += arr[i]
		ans1 += 1
	if j > 0:
		ans1 = 9999999999999999999999999999999999999
	ans2 = b * k
	j = n + b * prefix[k - 1]
	for i in range(k):
		if j <= 0:
			break
		j += arr[i]
		ans2 += 1
	if j > 0:
		ans2 = 9999999999999999999999999999999999999
	ans3 = c * k
	j = n + c * prefix[k - 1]
	for i in range(k):
		if j <= 0:
			break
		j += arr[i]
		ans3 += 1
	if j > 0:
		ans3 = 9999999999999999999999999999999999999
	print(min(ans1, ans2, ans3))


def solve(d, h):
	hp_delta_for_round = sum(d)
	min_hp_in_round = 0
	sum_of_minutes = 0
	for minute in d:
		sum_of_minutes += minute
		min_hp_in_round = min(min_hp_in_round, sum_of_minutes)
	target = -min_hp_in_round
	if hp_delta_for_round >= 0 and h > target:
		return None
	remaining_hp = h
	minutes = 0
	if h > target:
		completed_rounds = (h - target) // -hp_delta_for_round
		remaining_hp = h + completed_rounds * hp_delta_for_round
		minutes = completed_rounds * len(d)
	while remaining_hp > 0:
		remaining_hp += d[minutes % len(d)]
		minutes += 1
	return minutes
(h, n) = map(int, input().split())
d = [int(x) for x in input().split()]
result = solve(d, h)
print(-1 if result is None else result)


import sys
(h, n) = tuple(map(int, input().split()))
round = list(map(int, input().split()))
run = 0
maxv = 0
for i in round:
	run += i
	maxv = min(maxv, run)
total = run
if total >= 0:
	if -1 * maxv < h:
		print(-1)
		sys.exit()
if total != 0:
	count = (1 - h - maxv) // total * n
else:
	count = -1
if count < 0:
	count = 0
	sofar = h
else:
	sofar = count // n * total + h
while sofar > 0:
	sofar += round[count % n]
	count += 1
print(count)


import math
import sys
[H, n] = [int(i) for i in input().split()]
d = [int(j) for j in input().split()]
total = sum(d)
tmp_sum = 0
ans = pow(10, 12) * 200000 + 1
for x in range(len(d)):
	tmp_sum += d[x]
	if H + tmp_sum <= 0:
		ans = x + 1
		break
	elif total < 0:
		val = x + 1 + math.ceil(abs(-H - tmp_sum) / abs(total)) * n
		ans = min(ans, val)
if ans == pow(10, 12) * 200000 + 1:
	print(-1)
else:
	print(ans)


HN = list(map(int, input().split()))
H = HN[0]
n = HN[1]
lst = list(map(int, input().split()))
Hcopy = H
count = 1
for i in lst:
	Hcopy = Hcopy + i
	if Hcopy <= 0:
		print(count)
		quit()
	count += 1
smalles = 100
pref = 0
x = 0
for i in lst:
	pref += i
	if pref < smalles:
		smalles = pref
sm = Hcopy - H
if sm >= 0:
	print(-1)
	quit()
Hcopy = H + smalles
count = 0
k = Hcopy / (-1 * sm)
if int(k) != k:
	H = H + int(k + 1) * sm
	count += int(k + 1) * n
else:
	H = H + k * sm
	count += int(k) * n
for i in lst:
	count += 1
	H = H + i
	if H <= 0:
		break
print(count)


franxx = input()
franxx = franxx.split()
pa_U_dara = int(franxx[0])
life = int(franxx[1])
darling = input()
darling = darling.split()
darling[0] = int(darling[0])
kaguya = darling[0]
chika = -darling[0]
for i in range(1, life):
	darling[i] = int(int(darling[i]) + darling[i - 1])
	kaguya = darling[i]
	chika = max(chika, -kaguya)
flat = 0
if kaguya != 0:
	flat = max(0, -(max(pa_U_dara - chika, 0) // kaguya))
pa_U_dara += kaguya * flat
chest = -1
flat *= life
for i in range(0, life):
	if pa_U_dara + darling[i] <= 0:
		chest = i + 1
		break
print(flat + chest)


import sys
(h, n) = str.split(input(), ' ')
h = int(h)
n = int(n)
arr = str.split(input(), ' ')
rndmh = int(arr[0])
rndmhi = 0
rndsum = 0
if h <= -rndmh:
	print(rndmhi + 1)
	sys.exit(0)
for i in range(0, int(n)):
	rndsum = rndsum + int(arr[i])
	if rndmh > rndsum:
		rndmh = rndsum
		rndmhi = i
		if h <= -rndmh:
			print(rndmhi + 1)
			sys.exit(0)
h = h + rndmh
if rndsum >= 0:
	print(-1)
	sys.exit(0)
ans = (h - rndsum - 1) // -rndsum * n
h = h + rndsum * ((h - rndsum - 1) // -rndsum)
h = h - rndmh
rndmhi = 0
rndsum = 0
rndmh = int(arr[0])
if h <= -rndmh:
	print(ans + rndmhi + 1)
	sys.exit(0)
for i in range(0, n):
	rndsum = rndsum + int(arr[i])
	if rndmh > rndsum:
		rndmh = rndsum
		rndmhi = i
		if h <= -rndmh:
			print(ans + rndmhi + 1)
			sys.exit(0)
if h <= -rndmh:
	print(ans + rndmhi + 1)
	sys.exit(0)


(H, n) = map(int, input().split())
s = [int(x) for x in input().split()]
sumu = 0
arr1 = []
for i in range(0, len(s)):
	sumu += s[i]
	arr1.append(sumu)
arr = min(arr1)
if arr >= 0:
	print('-1')
elif H + arr > 0 and sumu >= 0:
	print('-1')
elif H + arr <= 0:
	for i in range(0, len(arr1)):
		if H + arr1[i] <= 0:
			print(i + 1)
			break
else:
	t = H + arr
	ans = 0
	if sumu != 0:
		if t % abs(sumu) == 0:
			ans = t // abs(sumu) * n
		else:
			ans = t // abs(sumu) * n
			ans = ans + n
	t = ans // n * abs(sumu)
	for i in range(0, len(arr1)):
		ans = ans + 1
		if t - arr1[i] >= H:
			break
	print(ans)


from sys import stdin, stdout
from math import ceil
for t in range(1):
	(H, n) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	sm = sum(a)
	ps = 0
	ans = float('inf')
	if sm >= 0:
		for i in range(n):
			ps += a[i]
			if ps + H <= 0:
				ans = i + 1
				break
		print(ans if ans != float('inf') else -1)
		continue
	for i in range(n):
		ps += a[i]
		if ps < 0:
			if H + ps <= 0:
				round = 0
			else:
				round = ceil((H + ps) / -sm)
			ans = min(ans, round * n + i + 1)
	print(ans if ans != float('inf') else -1)


(h, n) = map(int, input().split())
a = list(map(int, input().split()))
mi = 0
sum = 0
for i in range(n):
	sum += a[i]
	if sum < mi:
		mi = sum
if -mi < h and sum >= 0:
	print(-1)
elif sum >= 0:
	i = 0
	while i < n and h > 0:
		h += a[i]
		i += 1
	print(i)
else:
	sum = abs(sum)
	d = max((h + mi) // sum, 0)
	cnt = d * n
	h -= sum * d
	i = 0
	while h > 0:
		h += a[i]
		i = (i + 1) % n
		cnt += 1
	print(cnt)


import sys
import math
(hp, m) = [int(s) for s in input().split()]
array = [int(s) for s in input().split()]
pref = [0]
for i in range(len(array)):
	pref.append(pref[-1] + array[i])
pref = pref[1:]
min_ = min(pref)
if min_ >= 0:
	print(-1)
	sys.exit(0)
if hp > abs(min_):
	if pref[-1] >= 0:
		print(-1)
		sys.exit(0)
	n = math.ceil((hp - abs(min_)) / abs(pref[-1]))
	add = hp - n * abs(pref[-1])
	for i in range(len(pref)):
		if pref[i] < 0 and add <= abs(pref[i]):
			idx = i
			break
	print(n * m + idx + 1)
else:
	for i in range(len(pref)):
		if pref[i] < 0 and abs(pref[i]) >= hp:
			idx = i
			break
	print(idx + 1)


h = input().split()
d = [int(i) for i in input().split()]
p = []
p.append(int(h[0]))
c = 1
for i in range(1, 1 + int(h[1])):
	p.append(p[i - 1] + d[i - 1])
	if p[i] <= 0:
		c = 0
		print(i)
		break
p = p[1:]
if c == 1:
	c = sum(d)
	if c >= 0:
		print(-1)
	else:
		c *= -1
		t = min(p)
		t = t // c if t % c == 0 else t // c + 1
		for i in range(int(h[1])):
			p[i] -= t * c
			if p[i] <= 0:
				print(int(h[1]) * t + i + 1)
				break


def main():
	(h, n) = map(int, input().split())
	d = [int(i) for i in input().split()]
	pref = [d[0]]
	for i in range(1, n):
		pref.append(d[i] + pref[i - 1])
	val = min(pref)
	s = pref[n - 1]
	if val >= 0 or (abs(val) < h and s >= 0):
		print(-1)
	else:
		ans = 0
		if abs(val) < h:
			ans = (h + val) // abs(s) * n
		h += ans * s // n
		for i in range(2 * n):
			if h <= 0:
				print(ans)
				return 0
			ans += 1
			h += d[i % n]
		if h <= 0:
			print(ans)
			return 0
main()


(h, n) = list(map(int, input().split()))
d = list(map(int, input().split()))
s = 0
l = d[0]
a = []
for i in range(n):
	s += d[i]
	l = min(s, l)
import math
if s >= 0 and h + l > 0:
	print(-1)
else:
	k = 0
	if h + l > 0:
		k += n * math.ceil((h + l) / abs(s))
		h += math.ceil((h + l) / abs(s)) * s
	for i in range(n):
		k += 1
		h += d[i]
		if h <= 0:
			print(k)
			break


from itertools import accumulate

def multiplechecker(x, common_difference):
	if x * sum_ >= required:
		return True
	else:
		return False
(H, n) = input().split()
(H, n) = [int(H), int(n)]
frequency = 0
hitpoint = [int(g) for g in input().split()]
freq = list(accumulate(hitpoint))
sum1 = sum(hitpoint)
sum_ = abs(sum1)
if sum1 > 0 and abs(min(freq)) < H:
	print(-1)
else:
	count = 0
	for i in hitpoint:
		if i < 0:
			count += i
	required = H + min(freq)
	beg = 0
	last = 1000000000000
	while beg < last:
		mid = (beg + last) // 2
		counter = multiplechecker(mid, sum_)
		if counter == True:
			last = mid
		else:
			beg = mid + 1
	answer = H - sum_ * last
	tracker = 0
	if beg == 0 or beg == 1000000000000:
		for i in hitpoint:
			answer += i
			tracker += 1
			if answer <= 0:
				outputs = tracker
				break
			else:
				outputs = -1
		print(outputs)
	else:
		for i in hitpoint:
			answer += i
			tracker += 1
			if answer <= 0:
				break
		print(n * beg + tracker)


def main():
	ans = 0
	(h, n) = map(int, input().split())
	d = [0]
	d += list(map(int, input().split()))
	inf = 4557430888798830399
	maxx = inf
	for i in range(1, n + 1):
		d[i] += d[i - 1]
		maxx = min(d[i], maxx)
	if h + maxx > 0 and d[n] >= 0:
		print(-1)
		return 0
	(l, r) = (0, inf)
	while l <= r:
		mid = l + r >> 1
		if h + maxx <= 0:
			break
		if h + d[n] * mid + maxx <= 0:
			r = mid - 1
		else:
			l = mid + 1
	ans += l * n
	h += l * d[n]
	for i in range(1, n + 1):
		if h + d[i] <= 0:
			ans += i
			print(ans)
			return 0
main()


(H, n) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
sm = 0
gap = 0
h = H
for (i, e) in enumerate(arr):
	sm -= e
	h += e
	if h <= 0:
		print(i + 1)
		exit()
	gap = max(gap, sm)
if sm <= 0:
	print(-1)
	exit()
whole = (H - gap) // sm
H -= whole * sm
res = whole * n
i = 0
while H > 0:
	H += arr[i % n]
	res += 1
	if H <= 0:
		print(res)
		break
	i += 1


(H, n) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = -sum(a)
c = 0
ma = 0
flag = True
for (i, x) in enumerate(a):
	c -= x
	ma = max(c, ma)
	if ma >= H:
		print(i + 1)
		flag = False
		break
if flag:
	if b <= 0:
		print(-1)
	else:
		res = 0
		div = (H - ma) // b
		mod = H - b * div
		res += n * div
		if mod != 0:
			flag = True
			cnt2 = 0
			while flag:
				for x in a:
					cnt2 += 1
					mod += x
					if mod <= 0:
						flag = False
						break
			res += cnt2
		print(res)


from sys import exit
(h, n) = map(int, input().split())
h1 = h
d = list(map(int, input().split()))
sm = sum(d)
mn = 1000000000000.0
c = 0
ind = 0
for i in range(len(d)):
	c += d[i]
	if mn > c:
		mn = c
		ind = i + 1
c = 0
for i in d:
	h1 += i
	c += 1
	if h1 <= 0:
		print(c)
		exit(0)
if h1 >= h:
	print(-1)
	exit(0)
r = (h + mn) // -sm
h -= r * abs(sm)
c = 0
while True:
	for i in d:
		if h <= 0:
			print(c + r * n)
			exit(0)
		h += i
		c += 1


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(h, n) = map(int, input().split())
ch = 0
curr = 0
mn = 0
a = list(map(int, input().split()))
for i in range(n):
	curr += a[i]
	mn = min(mn, curr)
	if h + curr <= 0:
		print(i + 1)
		ch = 1
		break
if ch == 0:
	if curr >= 0:
		print(-1)
	else:
		curr = -curr
		copy = h
		copy += mn
		a = a + a
		j = copy // curr
		copy %= curr
		copy -= mn
		r = j * n
		for i in a:
			copy += i
			r += 1
			if copy <= 0:
				break
		print(r)


import sys
import collections
import math
import heapq
from operator import itemgetter

def getint():
	return int(input())

def getints():
	return [int(x) for x in input().split(' ')]
(H, n) = getints()
d = getints()
result = -1
roundDelta = 0
roundMin = float('inf')
for x in d:
	roundDelta += x
	roundMin = min(roundMin, roundDelta)
if roundMin >= 0:
	result = -1
else:
	t = 0
	while t < n:
		H += d[t]
		t += 1
		if H <= 0:
			break
	if H <= 0:
		result = t
	elif roundDelta >= 0:
		result = -1
	else:
		roundCount = max(0, (H + roundMin) // -roundDelta - 1)
		t += n * roundCount
		H += roundCount * roundDelta
		while H > 0:
			H += d[t % n]
			t += 1
		result = t
print(str(result))


import math
(h, n) = [int(item) for item in input().split()]
d = [int(item) for item in input().split()]
s = sum(d)

def solve():
	cur = 0
	v = float('inf')
	for i in range(n):
		cur += d[i]
		v = min(v, cur)
	if v + h <= 0:
		cur = h
		for i in range(n):
			cur += d[i]
			if cur <= 0:
				return i + 1
	if s >= 0:
		cur = h
		for i in range(n):
			cur += d[i]
			if cur <= 0:
				return i + 1
		return -1
	ans = math.ceil((v + h) / -s) * n
	cur = h + math.ceil((v + h) / -s) * s
	for i in range(n):
		cur += d[i]
		if cur <= 0:
			return ans + 1
		ans += 1
print(solve())


(h, n) = map(int, input().split())
m = list(map(int, input().split()))
x = 0
t = 0
time = 0
for i in range(n):
	x += m[i]
	if x < t:
		t = x
		time = i + 1
flag = 0
ans = 0
if h + t > 0 and x >= 0:
	print(-1)
elif h + t <= 0:
	for i in range(n):
		ans += 1
		h += m[i]
		if h <= 0:
			break
	print(ans)
else:
	ans = time
	h += t
	ans += n * (h // -x)
	h += x * (h // -x)
	while h > 0:
		h += m[ans % n]
		ans += 1
		if h <= 0:
			break
	print(ans)


def main():
	(total_hp, n) = map(int, input().split())
	d = list(map(int, input().split()))
	c = d.copy()
	for i in range(1, n):
		c[i] += c[i - 1]
	for i in range(n):
		if total_hp + c[i] <= 0:
			print(i + 1)
			return
	if c[-1] >= 0:
		print(-1)
		return
	(min_val, round_dmg) = (-min(c), -c[-1])
	temp_round = (total_hp - min_val + (round_dmg - 1)) // round_dmg
	ret = temp_round * n
	total_hp -= temp_round * round_dmg
	for i in range(n):
		if total_hp + c[i] <= 0:
			ret += i + 1
			break
	print(ret)
main()


def main():
	(h, n) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	sum_value = sum(arr)
	(cur_value, min_value) = (h, h)
	for v in arr:
		cur_value += v
		min_value = min(min_value, cur_value)
	if min_value > 0 and sum_value >= 0:
		print(-1)
		return 0
	if min_value <= 0:
		n_cycles = 0
	else:
		n_cycles = 1 + (min_value - 1) // -sum_value
	answer = n_cycles * len(arr)
	cur_value = h + n_cycles * sum_value
	for v in arr:
		cur_value += v
		answer += 1
		if cur_value <= 0:
			break
	print(answer)
main()


def solve():
	(h, n) = map(int, input().split())
	a = list(map(int, input().split()))
	sum = 0
	nowh = h
	mi = 1e+18
	for i in range(n):
		sum += a[i]
		nowh += a[i]
		if nowh <= 0:
			print(int(i + 1))
			return 0
		mi = min(mi, sum)
	if sum >= 0:
		print(int(-1))
		return 0
	ok = 10 ** 12
	ng = 0
	while abs(ok - ng) > 1:
		mid = (ok + ng) // 2
		rest = h + sum * mid
		if rest <= 0:
			ok = mid
		elif rest <= abs(mi):
			ok = mid
		else:
			ng = mid
	nowh = h + sum * ok
	if nowh <= 0:
		print(int(ok * n))
		return
	for i in range(n):
		nowh += a[i]
		if nowh <= 0:
			print(int(ok * n + i + 1))
			return
solve()


[h, n] = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
h1 = h
for i in range(n):
	h1 += d[i]
	if h1 <= 0:
		print(i + 1)
		quit()
sum = [0] * n
sum[0] = d[0]
for i in range(1, n, 1):
	sum[i] = sum[i - 1] + d[i]
max_dmg = min(sum)
if sum[n - 1] >= 0:
	print(-1)
	quit()
h1 = h + max_dmg
rounds = h1 // -sum[n - 1]
left = h - rounds * -sum[n - 1]
idx = 0
while left > 0:
	left = left + d[idx % n]
	idx += 1
print(rounds * n + idx)


import math
(hp, n) = [int(x) for x in input().split()]
hits = [int(x) for x in input().split()]
cum_hits = [0] * n
cum_hits[0] = hits[0]
for i in range(1, n):
	cum_hits[i] = cum_hits[i - 1] + hits[i]
min_ = min(cum_hits)
if abs(min_) >= hp:
	i = 0
	count = 0
	while hp > 0:
		hp = hp + hits[i]
		count = count + 1
		i = i + 1
	print(count)
else:
	s = cum_hits[-1]
	if s >= 0:
		print(-1)
	else:
		rounds = math.ceil(1.0 * (hp - abs(min_)) / abs(s))
		hp = hp - rounds * abs(s)
		count = 0
		i = 0
		while hp > 0:
			hp = hp + hits[i]
			count = count + 1
			i = i + 1
		print(rounds * n + count)


(health, minutes) = list(map(int, input().split()))
change = list(map(int, input().split()))
max = int(1000000000000000.0)
mini = max
sum = 0
ans = 0
current = health
for f in change:
	sum += f
	mini = min(mini, sum)
if mini >= 0:
	print(-1)
	exit(0)
rem = health
if health > abs(mini):
	if sum >= 0:
		print(-1)
		exit(0)
	else:
		sum = -sum
		ans = int((health + mini) / sum)
		if int((health + mini) % sum) != 0:
			ans += 1
		rem = health - sum * ans
c = 1
for f in change:
	rem += f
	if rem <= 0:
		print(int(ans * minutes + c))
		exit(0)
	c += 1


import sys, math, queue
sys.setrecursionlimit(1000000)
(h, n) = map(int, input().split())
d = list(map(int, input().split()))
s = sum(d)
if s >= 0:
	hc = h
	for i in range(n):
		hc += d[i]
		if hc <= 0:
			print(i + 1)
			exit()
	print(-1)
	exit()
ans = []
x = 0
for i in range(n):
	x += d[i]
	if h + x <= 0:
		a = i + 1
	else:
		a = i + 1 + n * math.ceil((h + x) / abs(s))
	ans.append(a)
print(min(ans))


import math

def solve():
	(H, n) = [int(x) for x in input().split(' ')]
	d = [int(x) for x in input().split(' ')]
	s = 0
	m = 0
	for di in d:
		s += di
		if s < m:
			m = s
	if H + m <= 0:
		t = 0
		for di in d:
			H += di
			t += 1
			if H <= 0:
				print(t)
				return
	elif s >= 0:
		print(-1)
	else:
		loop = math.ceil((H + m) / -s)
		remains = H + s * loop
		t = n * loop
		for di in d:
			remains += di
			t += 1
			if remains <= 0:
				print(t)
				return
		print(-1)
solve()


from math import *
(h, n) = map(int, input().split())
a = list(map(int, input().split()))
k = 0
s = 0
mas = 10 ** 18
for i in range(n):
	s += a[i]
	k += 1
	if s < mas:
		mas = s
	h += a[i]
	if h <= 0:
		print(k)
		exit(0)
if s >= 0:
	print(-1)
	exit(0)
k += n * ceil(max(h + mas, 0) / -s)
h += s * ceil(max(h + mas, 0) / -s)
for i in range(n):
	s += a[i]
	h += a[i]
	k += 1
	if h <= 0:
		print(k)
		exit(0)


(h, n) = map(int, input().split())
l = list(map(int, input().split()))
c = h
test = 1
m = 0
ma = 1000000 * n + 1
indice = -1
for i in range(n):
	m += l[i]
	if m < ma:
		ma = m
		indice = i
for i in range(n):
	c += l[i]
	if c <= 0:
		test = 0
		k = i + 1
		break
if test == 0:
	print(k)
elif sum(l) >= 0:
	print(-1)
else:
	res = (h + ma) // -sum(l) * n
	if res // n * sum(l) + h + ma <= 0:
		c = h + res // n * sum(l)
		for i in range(n):
			c += l[i]
			if c <= 0:
				k = i + 1
				break
		print(res + k)
	else:
		c = h + (res // n + 1) * sum(l)
		for i in range(n):
			c += l[i]
			if c <= 0:
				k = i + 1
				break
		print(res + n + k)


(H, n) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
m = 0
q = 0
for i in a:
	q += i
	if q < m:
		m = q
if s >= 0:
	for i in range(n):
		H += a[i]
		if H <= 0:
			print(i + 1)
			break
	else:
		print(-1)
else:
	s *= -1
	h = H + m
	if h > 0:
		ans = h // s
		H -= ans * s
		a *= 2
		for i in range(2 * n):
			H += a[i]
			if H <= 0:
				print(ans * n + i + 1)
				break
		else:
			print('oops')
	else:
		for i in range(n):
			H += a[i]
			if H <= 0:
				print(i + 1)
				break


from functools import reduce
mi = lambda : [int(i) for i in input().split()]
flat = lambda l: reduce(lambda a, b: a + b, l)
(h, n) = mi()
d = mi()
if n == 1:
	if d[0] >= 0:
		print(-1)
	else:
		print((h - d[0] - 1) // -d[0])
	exit(0)
changes = [0] * n
changes[0] = -d[0]
for i in range(1, n):
	changes[i] = changes[i - 1] - d[i]
ch = sum(d)
bch = max(changes)
if bch >= h:
	r = 0
	for i in d:
		h += i
		r += 1
		if h <= 0:
			break
	print(r)
	exit(0)
if ch >= 0:
	print(-1)
	exit(0)
r = 0
rounds = (h - bch - ch - 1) // -ch
h += rounds * ch
r += rounds * n
for i in d:
	h += i
	r += 1
	if h <= 0:
		break
print(r)


import sys
from math import ceil

def unique(lst):
	return dict(((o, o) for o in lst)).values()

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		h = self.next_int()
		n = self.next_int()
		x = [self.next_int() for _ in range(0, n)]
		for i in range(0, n):
			if i > 0:
				x[i] += x[i - 1]
			if h + x[i] <= 0:
				print(i + 1)
				return
		if x[-1] >= 0:
			print(-1)
			return
		rd = int(ceil((h + min(x)) / -x[-1]))
		h += x[-1] * rd
		for i in range(0, n):
			if h + x[i] <= 0:
				print(i + 1 + rd * n)
				return
		print('!!' + str(rd))
Main().solve()


import math
(H, n) = map(int, input().split())
D = list(map(int, input().split()))
h = H
ans = 0
for i in range(n):
	h += D[i]
	if h <= 0:
		ans = i + 1
		break
if ans != 0:
	print(ans)
else:
	a = H
	ans = 0
	pre = [D[0]]
	for i in range(1, n):
		pre.append(pre[i - 1] + D[i])
	if abs(min(pre)) < H and pre[-1] >= 0:
		print('-1')
	else:
		if H > abs(min(pre)):
			a = math.ceil((H + min(pre)) / abs(pre[-1]))
			H += a * pre[-1]
		ans = a * n
		for i in range(len(pre)):
			if pre[i] <= -H:
				ans += i + 1
				break
		print(ans)


(H, n) = input().split()
arr = list(map(int, input().split()))
(H, n) = (int(H), int(n))

def minute(H, n, arr):
	Sum = 0
	Min = arr[0]
	for i in range(n):
		Sum += arr[i]
		if H + Sum <= 0:
			return i + 1
		Min = min(Sum, Min)
	if Sum >= 0:
		return -1
	if (H + Min) % abs(Sum) == 0:
		rounds = (H + Min) // abs(Sum)
	else:
		rounds = (H + Min) // abs(Sum) + 1
	H += rounds * Sum
	Sum = 0
	for i in range(n):
		Sum += arr[i]
		if H + Sum <= 0:
			return rounds * n + i + 1
print(minute(H, n, arr))


(h, n) = list(map(lambda x: int(x), input().split(' ')))
d = list(map(lambda x: int(x), input().split(' ')))
for i in range(1, n):
	d[i] += d[i - 1]
for i in range(n):
	if h <= -d[i]:
		print(i + 1)
		h = -1
		break
if h == -1:
	pass
elif d[n - 1] >= 0:
	print('-1')
else:
	sum = -d[n - 1]
	ans = 100000000000000000000
	for i in range(n):
		ans = min(ans, ((h + d[i] - 1) // sum + 1) * n + i + 1)
	print(ans)


import sys
end = sys.exit
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
temp = n
minn = n
for i in range(k):
	if temp <= 0:
		print(i)
		end()
	minn = min(minn, temp)
	temp += l[i]
one_round = sum(l)
if one_round >= 0:
	print(-1)
	end()
rounds = (minn - one_round - 1) // -one_round
n += rounds * one_round
for i in range(k):
	if n <= 0:
		print(rounds * k + i)
		end()
	n += l[i]