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