#include <bits/stdc++.h>
using namespace std;
int num[110];
int ans[110];
int main() {
  int i, j, k, n;
  while (~scanf("%d%d", &n, &k)) {
    int out = 0;
    memset(num, 0, sizeof(num));
    memset(ans, 0, sizeof(ans));
    for (i = 1; i <= n; i++) {
      cin >> num[i];
      num[i] -= 1;
      ans[i % k] += num[i];
    }
    int group = n / k;
    double rate;
    for (i = 0; i < k; i++) {
      if (group > 2 * ans[i]) {
        out += ans[i];
      } else {
        out += group - ans[i];
      }
    }
    cout << out << endl;
  }
  return 0;
}
