#include <bits/stdc++.h>
using namespace std;
int t1[105], t2[105];
int a[105];
int main() {
  int n, k, i;
  scanf("%d%d", &n, &k);
  memset(t1, 0, sizeof(t1));
  memset(t2, 0, sizeof(t2));
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1)
      t1[i % k]++;
    else
      t2[i % k]++;
  }
  int sum = 0;
  for (i = 0; i < k; i++) {
    sum += min(t1[i], t2[i]);
  }
  printf("%d\n", sum);
  return 0;
}
