#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i, j, ans, one, two;
  int* a;
  vector<int> ch;
  cin >> n >> k;
  a = new int[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  i = 1;
  while (i <= k) {
    j = i + k;
    while (j <= n) {
      if (a[j] != a[i]) {
        ch.push_back(i);
        break;
      }
      j = j + k;
    }
    i++;
  }
  ans = 0;
  for (i = 0; i < ch.size(); i++) {
    one = 0;
    j = ch[i];
    while (j <= n) {
      if (a[j] == 2) {
        one++;
      }
      j = j + k;
    }
    two = 0;
    j = ch[i];
    while (j <= n) {
      if (a[j] == 1) {
        two++;
      }
      j = j + k;
    }
    ans = ans + min(one, two);
  }
  cout << ans << "\n";
}
