#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
int a[MAXN];
int main() {
  int n, k;
  while (scanf("%d%d", &n, &k) != EOF) {
    for (int i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    int ans = 0;
    for (int i = 0; i < k; i++) {
      int j, cnt = 0;
      for (j = i; j < n; j += k) {
        if (a[j] == 1) cnt++;
      }
      ans += min(cnt, n / k - cnt);
    }
    printf("%d\n", ans);
  }
  return 0;
}
