#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, sum = 0;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 0; j < k; j++) {
    int c1 = 0, c2 = 0;
    for (int i = j; i < n; i += k) {
      if (a[i] == 1)
        c1++;
      else
        c2++;
    }
    (c1 > c2) ? (sum += c2) : (sum += c1);
  }
  cout << sum << endl;
}
