#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, t, s, z[2], a[105];
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  s = 0;
  for (i = 0; i < k; i++) {
    memset(z, 0, sizeof(z));
    for (t = i; t < n; t += k) z[a[t] - 1]++;
    s += min(z[0], z[1]);
  }
  printf("%d\n", s);
}
