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