#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  vector<vector<int>> vv(k);
  int j = 0;
  for (int i = 0; i < n; i++) {
    vv[j].push_back(v[i]);
    j++;
    if (j == k) j = 0;
  }
  j = 0;
  int count = 0;
  for (j = 0; j < k; j++) {
    int c1 = 0, c2 = 0;
    for (int i = 0; i < n / k; i++) {
      if (vv[j][i] == 1)
        c1++;
      else
        c2++;
    }
    if (c1 != 0 && c2 != 0) {
      if (c1 < c2)
        count += c1;
      else
        count += c2;
    }
  }
  cout << count;
  return 0;
}
