struct node{
    int val, id;
};
node que[N];
int cost[N], head, tail, i, f[N];
int n, m;
int main(){
    n = read(), m = read();
    for(i = 1; i <= n; i++) cost[i] = read();
    head = 1, tail = 1;
    for(i = 1; i <= n; i++){
        while(que[head].id < i - m && head <= tail) head++;
        f[i] = que[head].val + cost[i];
        while(tail >= head && que[tail].val >= f[i]) tail--;
        que[++tail] = (node){f[i], i};
//        for(int j = head; j <= tail; j++) cout<<que[j].val<<" ";cout<<endl;
    }
    int ans = oo;
    for(int i = n - m + 1; i <= n; i++)
        ans = min(ans, f[i]);
    cout<<ans<<endl;
    return 0;
}