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