#include <bits/stdc++.h>
using namespace std;
const int SIZE = 111;
int d[SIZE];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < (n); ++i) {
    int(x);
    scanf("%d", &x);
    if (x == 1) d[i % k]++;
  }
  int an = 0;
  for (int i = 0; i < (k); ++i) an += min(d[i], n / k - d[i]);
  printf("%d\n", an);
  return 0;
}
