#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, m;
int a[N], f[N], q[N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) scanf("%d", &a[i]);
int hh = 0, tt = 0;
for (int i = 1; i <= n; i ++ )
{
if (q[hh] < i - m) hh ++;
f[i] = f[q[hh]] + a[i];
while (hh <= tt && f[q[tt]] >= f[i]) tt --;
q[ ++ tt] = i;
}
int res = INT_MAX;
for (int i = n - m + 1; i <= n; i ++ ) res = min(res, f[i]);
printf("%d", res);
return 0;
}
10-11
1003

04-17
1176

02-24
124

11-09
370
