#include <bits/stdc++.h>
using namespace std;
int CheckSingle(int num[], int n, int start, int k) {
  int sum[3] = {0};
  for (int i = start; i < n; i += k) sum[num[i]]++;
  return min(sum[1], sum[2]);
}
int Check(int num[], int n, int k) {
  int lmin = 0;
  for (int i = 0; i < k; i++) lmin += CheckSingle(num, n, i, k);
  return lmin;
}
int main() {
  int num[101], n, k;
  while (~scanf("%d %d", &n, &k)) {
    for (int i = 0; i < n; i++) scanf("%d", &num[i]);
    printf("%d\n", Check(num, n, k));
  }
  return 0;
}
