#include <bits/stdc++.h>
using namespace std;
const int MXN = 128;
int n, k;
int ar[MXN];
int solve() {
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int cnt[3] = {0};
    for (int p = i; p < n; p += k) {
      cnt[ar[p]]++;
    }
    ans += std::min(cnt[1], cnt[2]);
  }
  return ans;
}
int main() {
  while (scanf("%d %d", &n, &k) == 2) {
    for (int i = 0; i < n; i++) scanf("%d", ar + i);
    printf("%d", solve());
  }
}
