#include <bits/stdc++.h>
using namespace std;
int main() {
  int num[101][3], n, k, x;
  while (~scanf("%d %d", &n, &k)) {
    memset(num, 0, sizeof(num));
    for (int i = 0; i < n; i++) {
      scanf("%d", &x);
      num[i % k][x]++;
    }
    int lmin = 0;
    for (int i = 0; i < k; i++) lmin += min(num[i][1], num[i][2]);
    printf("%d\n", lmin);
  }
  return 0;
}
