#include <iostream>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int stairs[n + 1]; int time[n + 1]; // массивы для времени каждого мероприятия и потраченного времени;
for(int i = 1; i < n + 1; ++i) {
cin >> stairs[i];
if (i <= k + 1) time[i] = stairs[i];
}
time[0] = 0;
for(int i = 2; i <= n; ++i) {
if (i > k + 1) time[i] = time[i - 1] + stairs[i]; //начальный минимум;
for(int j = 2; j <= k+1; ++j) {
if (i - j >= 0) time[i] = min(time[i - j] + stairs[i], time[i]); // выбор минимально затраченного времени;
}
}
cout << time[n];
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CglpbnQgbiwgazsKCWNpbiA+PiBuID4+IGs7CglpbnQgc3RhaXJzW24gKyAxXTsgaW50IHRpbWVbbiArIDFdOyAvLyDQvNCw0YHRgdC40LLRiyDQtNC70Y8g0LLRgNC10LzQtdC90Lgg0LrQsNC20LTQvtCz0L4g0LzQtdGA0L7Qv9GA0LjRj9GC0LjRjyDQuCDQv9C+0YLRgNCw0YfQtdC90L3QvtCz0L4g0LLRgNC10LzQtdC90Lg7Cglmb3IoaW50IGkgPSAxOyBpIDwgbiArIDE7ICsraSkgewoJCWNpbiA+PiBzdGFpcnNbaV07IAoJCWlmIChpIDw9IGsgKyAxKSB0aW1lW2ldID0gc3RhaXJzW2ldOwoJfQoJdGltZVswXSA9IDA7IAoJZm9yKGludCBpID0gMjsgaSA8PSBuOyArK2kpIHsKCQlpZiAoaSA+IGsgKyAxKSB0aW1lW2ldID0gdGltZVtpIC0gMV0gKyBzdGFpcnNbaV07IC8v0L3QsNGH0LDQu9GM0L3Ri9C5INC80LjQvdC40LzRg9C8OwoJCWZvcihpbnQgaiA9IDI7IGogPD0gaysxOyArK2opIHsKCQkJaWYgKGkgLSBqID49IDApIHRpbWVbaV0gPSAgbWluKHRpbWVbaSAtIGpdICsgc3RhaXJzW2ldLCB0aW1lW2ldKTsgLy8g0LLRi9Cx0L7RgCDQvNC40L3QuNC80LDQu9GM0L3QviDQt9Cw0YLRgNCw0YfQtdC90L3QvtCz0L4g0LLRgNC10LzQtdC90Lg7CgkJfQoJfQoJY291dCA8PCB0aW1lW25dOwp9