#include <bits/stdc++.h>
int main() {
  int n, k, i, j, counter = 0;
  scanf("%d %d", &n, &k);
  int arr[n], counter1[1000] = {0}, counter2[1000] = {0};
  for (i = 0; i < n; i++) scanf("%d", &arr[i]);
  for (i = 0; i < k; i++) {
    for (j = i; j < n; j += k) {
      if (arr[j] == 1)
        counter1[i]++;
      else
        counter2[i]++;
    }
  }
  for (i = 0; i < k; i++) {
    if (counter1[i] > counter2[i]) {
      for (j = i; j < n; j += k) {
        if (arr[j] != 1) counter++;
      }
    } else
      for (j = i; j < n; j += k)
        if (arr[j] != 2) counter++;
  }
  printf("%d", counter);
  return 0;
}
