#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, k, a[N];
int main() {
  int ans = 0;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < k; i++) {
    int one = 0, two = 0;
    for (int j = i; j < n; j += k) {
      if (a[j] == 1)
        one++;
      else
        two++;
    }
    ans += min(one, two);
  }
  cout << ans << endl;
  return 0;
}
