public class MaxKPartitions {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] array = new int[n];
for (int i = 0; i < n ; i++) {
array[i]=sc.nextInt();
}
System.out.println(count(n,k,array));
}
public static int count(int n,int k,int[] array){
int prev_best_sum=0;
int prev_best_index=0;
int prev_sec_sum=0;
for (int i = 0; i < (n+k-1)/k ; i++) {
int curr_best_sum=prev_best_sum;
int curr_best_index=prev_best_index;
int curr_sec_sum=prev_sec_sum;
for (int j = i*k; j < (i+1)*k && j<n ; j++) {
int sum=0;
if(j-prev_best_index!=k){
sum=prev_best_sum+array[j];
}
else{
sum=prev_sec_sum+array[j];
}
if(sum>curr_best_index){
curr_sec_sum=curr_best_sum;
curr_best_sum=sum;
curr_best_index=j;
}
if(sum>curr_sec_sum){
curr_sec_sum=sum;
}
}
prev_best_sum=curr_best_sum;
prev_best_index=curr_best_index;
prev_sec_sum=curr_sec_sum;
}
return prev_best_sum;
}
}