#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll mod=1e9+7;
ll a[200010];
ll b[200010];
ll tc,i,j,k,n,m;
string s,s1,s2;
map<ll,ll> mpi;
map<ll,ll> mpj;
vector<ll> v;
int main(){
IOS
cin>>n>>k;
ll sum=0;
for(i=0;i<n;i++){
cin>>a[i];
sum+=a[i];
}
ll mx=-100;
for(i=0;i<n;i++){
if((i-k)>=0)
a[i]+=a[i-k];
mx=max(mx,a[i]);
}
cout<<sum-mx<<endl;
}