#include <iostream>
#include<algorithm>
using namespace std;
int main() {
int n , k ;
cin>>n>>k;
int a[n];
int total = 0 , minn=999999999;
for(int i =0 ; i<n ; i++)
{
cin>>a[i];
total +=a[i];
}
for(int i = 0 ; i< n; i++)
{
int sum = total ;
for(int j = i ; j<n ; j+=k)
sum -= a[j];
minn=min(sum,minn);
}
cout<<minn;
}