#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> e;
  int c = n;
  while (c--) {
    int v;
    cin >> v;
    e.push_back(v);
  }
  int cc = 0;
  for (int j = 0; j < k; j++) {
    int a = 0, b = 0;
    for (int i = j; i < n; i += k) {
      if (e[i] == 1)
        a++;
      else
        b++;
    }
    cc += min(a, b);
  }
  cout << cc;
  return 0;
}
