#include <bits/stdc++.h>
using namespace std;
int a[1000007];
int b[1000007];
int main() {
  int m, p;
  scanf("%d %d", &m, &p);
  int i, j;
  long long int ans = 0;
  for (i = 1; i <= m; i++) scanf("%d", a + i);
  for (i = 1; i <= p; i++) {
    j = i;
    while (j <= m) {
      b[a[j]]++;
      j = j + p;
    }
    if (b[1] <= b[2])
      ans = ans + b[1];
    else
      ans = ans + b[2];
    b[1] = 0, b[2] = 0;
  }
  printf("%lld\n", ans);
  return 0;
}
