#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[110];
  int n, k;
  while (scanf("%d %d", &n, &k) == 2) {
    int r = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int n1, n2;
    for (int i = 1; i <= k; i++) {
      n1 = 0;
      n2 = 0;
      for (int j = i; j <= n; j += k) {
        if (a[j] == 1)
          n1++;
        else
          n2++;
      }
      r += min(n1, n2);
    }
    cout << r << endl;
  }
  return 0;
}
