#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    int m = 0;
    for (int j = i; j < n; j += k) {
      if (a[j] == 1) {
        m++;
      }
    }
    ans += min(m, (n / k - m));
  }
  cout << ans << '\n';
}
