A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them.

The stones are located at integer distances from the banks. There are $a_i$ stones at the distance of $i$ units from the bank the frogs are currently at. Each stone can only be used once by one frog, after that it drowns in the water.

What is the maximum number of frogs that can cross the river, given that then can only jump on the stones?


-----Input-----

The first line contains two integers $w$ and $l$ ($1 \le l < w \le 10^5$) — the width of the river and the maximum length of a frog's jump.

The second line contains $w - 1$ integers $a_1, a_2, \ldots, a_{w-1}$ ($0 \le a_i \le 10^4$), where $a_i$ is the number of stones at the distance $i$ from the bank the frogs are currently at.


-----Output-----

Print a single integer — the maximum number of frogs that can cross the river.


-----Examples-----
Input
10 5
0 0 1 0 2 0 0 1 0

Output
3

Input
10 3
1 1 1 1 2 1 1 1 1

Output
3



-----Note-----

In the first sample two frogs can use the different stones at the distance $5$, and one frog can use the stones at the distances $3$ and then $8$.

In the second sample although there are two stones at the distance $5$, that does not help. The three paths are: $0 \to 3 \to 6 \to 9 \to 10$, $0 \to 2 \to 5 \to 8 \to 10$, $0 \to 1 \to 4 \to 7 \to 10$.

Difficulty: HARD

Solutions:
from math import *
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
import copy

def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())

def Function():
	(w, l) = li()
	a = li()
	a.reverse()
	s = sum(a[:l])
	min = s
	for i in range(l, w - 1):
		s += a[i]
		s -= a[i - l]
		if s < min:
			min = s
	print(min)
for _ in range(1):
	Function()


(w, l) = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(1, w - 1):
	a[i] = a[i] + a[i - 1]
ans = a[l - 1]
for i in range(l, w - 1):
	ans = min(ans, a[i] - a[i - l])
print(ans)


(w, l) = [int(i) for i in input().split(' ')]
a = [1000000000.0] * (w + 1)
entrada = [int(i) for i in input().split(' ')]
for i in range(1, w):
	a[i] = entrada[i - 1]
aux = [0] * len(a)
num = 0
for j in range(1, w + 1):
	if a[j] <= 0:
		continue
	if j <= l:
		aux[j] = a[j]
		continue
	d = j
	for k in range(j - l, d):
		if aux[k] < a[j] - aux[j]:
			num = aux[k]
		else:
			num = a[j] - aux[j]
		aux[k] = aux[k] - num
		aux[j] = aux[j] + num
		if aux[j] >= a[j]:
			break
print(aux[-1])


(w, l) = map(int, input().split())
a = list(map(int, input().split()))
f = s = sum((i for i in a[:l]))
for (i, b) in enumerate(a[l:]):
	s += b - a[i]
	f = min(s, f)
print(f)


(w, l) = map(int, input().split())
a = list(map(int, input().split()))
x = y = sum(a[:l])
for i in range(w - l - 1):
	y = y - a[i] + a[i + l]
	x = min(y, x)
print(x)


(w, l) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
o = sum(arr[:l])
O = o
for i in range(1, w - l):
	o = o - arr[i - 1]
	o += arr[i + l - 1]
	O = min(O, o)
print(O)


(l, w) = list(map(int, input().split()))
li = list(map(int, input().split()))
aa = []
tot = 0
for i in range(l - 1):
	tot += li[i]
	if i >= w:
		tot = tot - li[i - w]
	if i >= w - 1:
		aa.append(tot)
print(min(aa))


I = lambda : map(int, input().split())
(w, l) = I()
a = list(I())
c = s = sum(a[:l])
for i in range(w - l - 1):
	s = s - a[i] + a[i + l]
	c = min(c, s)
print(c)


(river_width, jump_len) = [int(x) for x in input().split(' ')]
stones = [int(x) for x in input().split(' ')]
(ans, current) = (-1, 0)
for (i, stone) in enumerate(stones):
	current += stone
	if i + 1 >= jump_len:
		ans = min(ans, current) if ans != -1 else current
		current -= stones[i + 1 - jump_len]
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(1, n - 1):
	l[i] += l[i - 1]
ans = l[k - 1]
for i in range(k, n - 1):
	ans = min(ans, l[i] - l[i - k])
print(ans)


(w, l) = [int(i) for i in input().split(' ')]
a = [2000000000.0] * (w + 1)
entrada = [int(i) for i in input().split(' ')]
for i in range(1, w):
	a[i] = entrada[i - 1]
b = [0] * len(a)
mv = 0
for p in range(1, w + 1):
	if a[p] <= 0:
		continue
	if p <= l:
		b[p] = a[p]
		continue
	d = p
	for u in range(p - l, d):
		if b[u] < a[p] - b[p]:
			mv = b[u]
		else:
			mv = a[p] - b[p]
		b[u] = b[u] - mv
		b[p] = b[p] + mv
		if b[p] >= a[p]:
			break
print(b[-1])


(w, l) = map(int, input().split())
A = list(map(int, input().split()))
A = [0] + A + [0]
dp = [0] * (w + 1)
for i in range(w):
	if i == 0:
		for j in reversed(range(1, l + 1)):
			dp[j] += A[j]
	else:
		for j in reversed(range(i + 1, min(i + l + 1, w + 1))):
			if j == w:
				dp[j] += dp[i]
				break
			else:
				ndpj = min(A[j], dp[j] + dp[i])
				dp[i] -= ndpj - dp[j]
				dp[j] = ndpj
				if dp[i] <= 0:
					break
print(dp[-1])


(w, l) = map(int, input().split())
a = list(map(int, input().split()))
(s, mn) = (0, 100000000000000000)
for i in range(l):
	s += a[i]
mn = min(mn, s)
for i in range(l, w - 1):
	s += a[i]
	s -= a[i - l]
	mn = min(mn, s)
print(mn)


import sys

def findMinSubSum(a, l):
	minim = sum(a[:l])
	current = minim
	for i in range(l, len(a)):
		current += a[i] - a[i - l]
		minim = min(current, minim)
	return minim
(w, l) = map(int, input().split())
a = list(map(int, input().split()))
print(findMinSubSum(a, l))


(n, jump) = map(int, input().split())
arr = list(map(int, input().split()))
(pt1, pt2) = (0, jump)
while pt2 < n - 1:
	count = 0
	flag = 0
	while pt1 < pt2:
		if count + arr[pt1] <= arr[pt2]:
			count += arr[pt1]
			arr[pt1] = 0
			pt1 += 1
		else:
			arr[pt1] -= max(0, arr[pt2] - count)
			flag = 1
			break
	if flag == 0:
		arr[pt2] = count
	pt2 += 1
	pt1 = max(pt1, pt2 - jump)
print(sum(arr[n - jump - 1:]))


(w, l) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s = res = sum(a[:l])
for i in range(l, w - 1):
	s += a[i] - a[i - l]
	res = min(res, s)
print(res)


inf = 2000000000
(w, l) = map(int, input().split())
aa = input().split()
a = [0 for i in range(w)]
dp = [0 for i in range(w + 1)]
su = [0 for i in range(w + 1)]
for i in range(1, w):
	a[i] = int(aa[i - 1])
for i in range(1, w):
	if i <= l:
		dp[i] = a[i]
	else:
		dp[i] = min(a[i], su[i - 1] - su[i - l - 1])
	su[i] = su[i - 1] + dp[i]
res = inf
for i in range(l, w):
	res = min(res, su[i] - su[i - l])
print(res)


from itertools import *
r = lambda : map(int, input().split())
(w, l) = r()
v = [0, *accumulate(r())]
print(min((v[i] - v[i - l] for i in range(l, w))))


(w, l) = (int(x) for x in input().split())
dist___rocks_nr = [int(x) for x in input().split()]
curr_l = 0
start_sum = sum(dist___rocks_nr[:l])
min_sum = start_sum
while True:
	if curr_l + l >= w - 1:
		break
	start_sum -= dist___rocks_nr[curr_l]
	start_sum += dist___rocks_nr[curr_l + l]
	curr_l += 1
	min_sum = min(start_sum, min_sum)
print(min_sum)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
threading.stack_size(10 ** 8)
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
sys.setrecursionlimit(300000)
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')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
(n, k) = map(int, input().split())
l = list(map(int, input().split()))

def check(mid):
	cur = 0
	for i in range(k - 1):
		cur += l[i]
	for i in range(n):
		if i + k - 1 < n - 1:
			cur += l[i + k - 1]
		else:
			break
		if i > 0:
			cur -= l[i - 1]
		if cur >= mid:
			continue
		else:
			return False
	return True
st = 0
end = sum(l)
ans = st
while st <= end:
	mid = (st + end) // 2
	if check(mid) == True:
		ans = mid
		st = mid + 1
	else:
		end = mid - 1
print(ans)


def f(n, l):
	m = len(l)
	if n == 1:
		return min(l)
	if n == m:
		return sum(l)
	ans = sum(l[:n])
	new = ans
	for i in range(1, m - n):
		new = new + l[i - 1 + n] - l[i - 1]
		if new < ans:
			ans = new
	return ans
(w, n) = list(map(int, input().split()))
l = list(map(int, input().split()))
print(f(n, l))


(w, l) = map(int, input().split())
a = tuple(map(int, input().split()))
sumat = sum(a[:l])
mini = sumat
for i in range(w - l - 1):
	sumat = sumat - a[i] + a[i + l]
	mini = min(mini, sumat)
print(mini)


(w, l) = list(map(int, input().split()))
a = list(map(int, input().split()))
minsegment = s = sum(a[:l])
for i in range(1, w - l):
	s = s - a[i - 1] + a[i + l - 1]
	minsegment = min(s, minsegment)
print(minsegment)


from sys import stdin
(w, l) = map(int, stdin.readline().split())
a = [0] + list(map(int, stdin.readline().split()))
c = [0 for _ in range(w)]
(i, j) = (1, 1)
C = 0
while j <= l:
	c[j] = a[j]
	a[j] = 0
	j += 1
while i < w:
	while j < w and a[j] == 0:
		j += 1
	if j - i > l:
		i += 1
		continue
	if j == w:
		C += c[i]
		c[i] = 0
	else:
		d = min(c[i], a[j])
		c[i] -= d
		a[j] -= d
		c[j] += d
	if c[i] == 0:
		i += 1
print(C)


def ii():
	return int(input())

def si():
	return input()

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

def li():
	return list(mi())

def Function():
	(w, l) = li()
	a = li()
	a.reverse()
	s = sum(a[:l])
	min = s
	for i in range(l, w - 1):
		s += a[i]
		s -= a[i - l]
		if s < min:
			min = s
	print(min)
for _ in range(1):
	Function()


import sys

def getAns(river, w, l):
	t_sum = 0
	for i in range(0, l):
		t_sum += river[i]
	min_val = t_sum
	for i in range(l, w - 1):
		t_sum = t_sum - river[i - l] + river[i]
		min_val = min(min_val, t_sum)
	return min_val
(w, l) = [int(x) for x in input().split()]
f_list = [int(x) for x in input().split()]
result = getAns(f_list, w, l)
print(result)


import sys
wl = input().split()
w = int(wl.pop(0))
l = int(wl.pop(0))
a = [int(i) for i in input().split()]
a = [0] + a
sun = 0
ans = 10 ** 9
for i in range(1, w):
	sun += a[i]
	if i >= l:
		ans = min(ans, sun)
		sun -= a[i - l + 1]
print(ans)


from collections import deque
(w, l) = map(int, input().split())
a = [0] + list(map(int, input().split())) + [0]
removable_que = deque([])
cnt = [0] * w
ans = 0
for pos in range(w - l, w):
	cnt[pos] = a[pos]
for pos in range(w - 1, 0, -1):
	if pos <= l:
		ans += cnt[pos]
		continue
	removable_que.appendleft(pos - l)
	val = cnt[pos]
	while removable_que and removable_que[-1] >= pos:
		removable_que.pop()
	while val > 0 and removable_que:
		poped_index = removable_que.popleft()
		d = a[poped_index] - cnt[poped_index]
		if d == 0:
			continue
		if d >= val:
			cnt[poped_index] += val
			val = 0
			removable_que.appendleft(poped_index)
			continue
		else:
			cnt[poped_index] += d
			val -= d
			continue
print(ans)


import sys
input = sys.stdin.readline
(w, l) = map(int, input().split())
a = [int(i) for i in input().split() if i != '\n']
ans = [sum(a[:l])]
for i in range(w - 1 - l):
	pq = ans[-1] + a[i + l] - a[i]
	ans.append(pq)
sys.stdout.write(str(min(ans)) + '\n')


input_string = input().split()
n = int(input_string[0])
l = int(input_string[1])
input_string = input().split()
v = []
for i in range(0, len(input_string)):
	v.append(int(input_string[i]))
dp = [0]
for i in range(1, len(v) + 1):
	dp.append(dp[i - 1] + v[i - 1])
ans = 1000000000000000000000000000
for i in range(l, len(dp)):
	ans = min(ans, dp[i] - dp[i - l])
print(ans)


import sys
read = lambda : map(int, sys.stdin.buffer.readline().split())
(w, l) = read()
a = list(read())
b = [0] * (w - 1)
ans = 0
j = 0
for i in range(l):
	(a[i], b[i]) = (0, a[i])
for i in range(w - 1):
	if b[i] == 0:
		continue
	if i + l >= w - 1:
		ans += b[i]
	else:
		j = max(i + 1, j)
		while j < w - 1 and j - i <= l and (b[i] > 0):
			m = min(b[i], a[j])
			a[j] -= m
			b[j] += m
			b[i] -= m
			if a[j] == 0:
				j += 1
print(ans)


(w, l) = [int(i) for i in input().split(' ')]
arr = [int(i) for i in input().split(' ')]
cummulative = [0 for i in range(len(arr) + 1)]
for i in range(len(arr)):
	cummulative[i + 1] = cummulative[i] + arr[i]
min_cut = 1000000009
for i in range(w - l):
	cut = cummulative[i + l] - cummulative[i]
	if cut < min_cut:
		min_cut = cut
print(min_cut)


Q = [int(x) for x in input().split(' ')]
w = Q[0]
l = Q[1]
A = [int(x) for x in input().split(' ')]
B = [0 for i in range(w - 1)]
i = 0
j = 0
for i in range(w - 1):
	if i < l:
		B[i] = A[i]
	else:
		while j < i:
			if j < i - l:
				j = i - l
			t = min(A[i] - B[i], B[j])
			B[i] += t
			B[j] -= t
			if B[j] == 0:
				j += 1
			else:
				break
print(sum(B[w - l - 1:]))


[w, l] = list(map(int, input().strip().split()))
ais = list(map(int, input().strip().split()))
winais = [0 for _ in range(w - l)]
s = sum(ais[:l])
winais[0] = s
for i in range(w - l - 1):
	s += ais[i + l] - ais[i]
	winais[i + 1] = s
print(min(winais))


def read_nums():
	return list(map(int, input().split()))
(w, l) = read_nums()
rocks = read_nums()
cur_sum = sum(rocks[0:l])
min_sum = cur_sum
for i in range(l, len(rocks)):
	cur_sum -= rocks[i - l]
	cur_sum += rocks[i]
	min_sum = min(min_sum, cur_sum)
print(min_sum)


def main():
	(w, l) = map(int, input().split())
	a = list(map(int, input().split()))
	dist = 0
	mdist = float('inf')
	for i in range(l):
		dist += a[i]
	mdist = min(mdist, dist)
	for i in range(l, w - 1):
		dist += a[i]
		dist -= a[i - l]
		mdist = min(mdist, dist)
	print(mdist)
	return
main()


from collections import Counter
import os
import sys
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys
import sys
import math
(n, l) = map(int, input().split())
arr = list(map(int, input().split()))
ptr = l
var = 1
m = sum(arr[:ptr])
val = m
ptr += 1
while ptr < n:
	val = val - arr[var - 1] + arr[ptr - 1]
	m = min(m, val)
	ptr += 1
	var += 1
print(m)


(w, l) = map(int, input().split())
a = list(map(int, input().split()))
prefix = [0] * (w - l)
prefix[0] = sum(a[:l])
for i in range(w - 1 - l):
	prefix[i + 1] += prefix[i] + a[i + l] - a[i]
print(min(prefix))


(w, l) = list(map(int, input().split()))
a = list(map(int, input().split()))
s = 0
for i in range(l):
	s += a[i]
c = 10 ** 20 + 1
for i in range(l, w - 1):
	c = min(c, s)
	s = max(0, s + a[i] - a[i - l])
c = min(c, s)
print(c)


import sys
(w, l) = [int(x) for x in input().split()]
use = [int(x) for x in input().split()]
m = sum(use[0:l])
s = m
for i in range(1, w - l):
	s = s - use[i - 1] + use[i + l - 1]
	if s < m:
		m = s
print(m)


(n, l) = list(map(int, input().split()))
stones = list(map(int, input().split()))
summ = sum(stones[:l])
minn = summ
for i in range(n - l - 1):
	summ = summ + stones[l + i] - stones[i]
	if summ < minn:
		minn = summ
print(minn)