/*
ye mera template hai
apna khud likho bc :P
*/
/*
Author : Sarvagya Agarwal
*/
#include<bits/stdc++.h>
using namespace std;
//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define int long long
#define mod 1000000007
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int power(int a , int b)
{
int res = 1 ;
while(b)
{
if(b%2) {
res = (res * a)%mod ;
}
b/=2 ;
a = (a*a)%mod ;
}
return res ;
}
//debug
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int n , k ;
const int inf = 1e18 ;
int dp[10005][2] , dp2[10005][2] ,arr[10005] ;
int32_t main()
{
fast;
cin >> n >> k ;
rep(i,1,n)cin >> arr[i] ;
dp[0][0] = dp[0][1] = 0 ;
for(int i = 1 ; i <= n ;++i) {
int min_cost = inf ;
for(int j = max(1ll,i-k) ; j < i ; ++j) {
min_cost = min(min_cost,dp[j][1]) ;
}
dp[i][0] = min_cost ;
dp[i][1] = arr[i] ;
if(i-k > 1ll) {
dp[i][1] += min(dp[i-k-1][0],dp[i-k-1][1]) ;
}
}
dp2[n+1][0] = dp2[n+1][1] = 0 ;
for(int i = n ; i >= 1 ;--i)
{
int min_cost = inf ;
for(int j = i + 1 ; j <= min(i+k,n);++j) {
min_cost = min(min_cost,dp2[j][1]) ;
}
dp2[i][0] = min_cost ;
dp2[i][1] = arr[i] ;
if(i+k < n) {
dp2[i][1] += min(dp2[i+k+1][0],dp2[i+k+1][1]) ;
}
}
int ans = inf ;
for(int i = 1 ; i <= n ; ++i) {
int cost = arr[i] ;
if(i-k > 1)cost += min(dp[i-k-1][0],dp[i-k-1][1]) ;
if(i+k < n)cost += min(dp2[i+k+1][0],dp2[i+k+1][1]) ;
ans = min(ans,cost) ;
}
cout << ans << endl;
return 0;
}
LyoKeWUgbWVyYSB0ZW1wbGF0ZSBoYWkKYXBuYSBraHVkIGxpa2hvIGJjIDpQCiovCgovKgpBdXRob3IgOiBTYXJ2YWd5YSBBZ2Fyd2FsCiovCgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKLy9kZWZpbmVzCiNkZWZpbmUgb3BlbmluIGZyZW9wZW4oImlucHV0LnR4dCIsInIiLHN0ZGluKQojZGVmaW5lIG9wZW5vdXQgZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCkKI2RlZmluZSBmYXN0IGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpO2Npbi50aWUoMCk7Y291dC50aWUoMCkKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSBpbnQgbG9uZyBsb25nCiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKI2RlZmluZSByZXAoaSx4LHkpIGZvciAoX190eXBlb2YoeCkgaT14O2k8PXk7aSsrKQojZGVmaW5lIGFsbChjKSAoYykuYmVnaW4oKSwoYykuZW5kKCkKI2RlZmluZSBmZiBmaXJzdAojZGVmaW5lIHNzIHNlY29uZAojZGVmaW5lIHBiIHB1c2hfYmFjawojZGVmaW5lIG1wIG1ha2VfcGFpcgoKaW50IHBvd2VyKGludCBhICwgaW50IGIpCnsKICAgIGludCByZXMgPSAxIDsKICAgIHdoaWxlKGIpCiAgICB7CiAgICAgICAgaWYoYiUyKSB7CiAgICAgICAgICAgIHJlcyA9IChyZXMgKiBhKSVtb2QgOwogICAgICAgIH0KICAgICAgICBiLz0yIDsKICAgICA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luX2Nvc3QgPSBtaW4obWluX2Nvc3QsZHBbal1bMV0pIDsKICAgICAgICB9CiAgICAgICAgZHBbaV1bMF0gPSBtaW5fY29zdCA7CiAgICAgICAgZHBbaV1bMV0gPSBhcnJbaV0gOwogICAgICAgIGlmKGktayA+IDFsbCkgewogICAgICAgICAgICBkcFtpXVsxXSArPSBtaW4oZHBbaS1rLTFdWzBdLGRwW2ktay0xXVsxXSkgOwogICAgICAgIH0KICAgIH0KICAgIGRwMltuKzFdWzBdID0gZHAyW24rMV1bMV0gPSAwIDsKICAgIGZvcihpbnQgaSA9IG4gOyBpID49IDEgOy0taSkKICAgIHsKICAgICAgICBpbnQgbWluX2Nvc3QgPSBpbmYgOwogICAgICAgIGZvcihpbnQgaiA9IGkgKyAxIDsgaiA8PSBtaW4oaStrLG4pOysraikgewogICAgICAgICAgICBtaW5fY29zdCA9IG1pbihtaW5fY29zdCxkcDJbal1bMV0pIDsKICAgICAgICB9CiAgICAgICAgZHAyW2ldWzBdID0gbWluX2Nvc3QgOwogICAgICAgIGRwMltpXVsxXSA9IGFycltpXSA7CiAgICAgICAgaWYoaStrIDwgbikgewogICAgICAgICAgICBkcDJbaV1bMV0gKz0gbWluKGRwMltpK2srMV1bMF0sZHAyW2kraysxXVsxXSkgOwogICAgICAgIH0KICAgIH0KICAgIGludCBhbnMgPSBpbmYgOwogICAgZm9yKGludCBpID0gMSA7IGkgPD0gbiA7ICsraSkgewogICAgICAgIGludCBjb3N0ID0gYXJyW2ldIDsKICAgICAgICBpZihpLWsgPiAxKWNvc3QgKz0gbWluKGRwW2ktay0xXVswXSxkcFtpLWstMV1bMV0pIDsKICAgICAgICBpZihpK2sgPCBuKWNvc3QgKz0gbWluKGRwMltpK2srMV1bMF0sZHAyW2kraysxXVsxXSkgOwogICAgICAgIGFucyA9IG1pbihhbnMsY29zdCkgOwogICAgfQogICAgY291dCA8PCBhbnMgPDwgZW5kbDsKICAgIHJldHVybiAwOwp9Cg==