#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ll n,k;
cin>>n>>k;
ll arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
ll mx=1e13,sum=0;
for(int j=0;j<n/k;j++){
ll x=j;
for(int i=0;i<n;i++){
if(i!=x)
sum+=arr[i];
else
x+=k;
}
if(mx>sum)
mx=sum;
sum=0;
}
cout<<mx;
return 0;
}