#include <bits/stdc++.h>
using namespace std;
const int N = 300010;
long long n, m, a, k;
long long s[N], num[N], t[N];
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
int main() {
  while (cin >> n >> k) {
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    int ans = 0;
    for (int j = 0; j < k; j++) {
      int a = 0, b = 0;
      for (int i = 0; i < n; i += k) {
        if (s[j + i] == 1)
          a++;
        else
          b++;
      }
      ans += min(a, b);
    }
    printf("%d\n", ans);
  }
  return 0;
}
