import java.util.Scanner; public class Solution3 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int k = scan.nextInt(); int[] a = new int[n]; for (int i = 0 ; i < n; i++) a[i] = scan.nextInt(); int cost = 0, tcost; for (int i = 0 ; i <= k ; i++) { tcost = 0; for (int j = i; j < n; j += k + 1) { tcost += a[j]; } if (tcost < cost || i == 0) cost = tcost; } System.out.println(cost); } }