#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
const int M = 10000 + 10;
const int Q = 1000 + 10;
const int A = 30 + 1;
int a[N];
int n, k, m;
int ans;
int b[N], c[N];
int x;
int main() {
  scanf("%d%d", &n, &k);
  for (int i(1); i <= (n); ++i) scanf("%d", a + i);
  for (int i(1); i <= (n); ++i) {
    x = i % k;
    if (a[i] == 1)
      b[x]++;
    else
      c[x]++;
  }
  for (int i(0); i < (k); ++i) ans += min(b[i], c[i]);
  printf("%d\n", ans);
  return 0;
}
