#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e4 + 20;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int a[105];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = 0, sum = 0;
  for (int i = 0; i < k; i++) {
    sum = 0;
    for (int j = i; j < n; j += k) {
      if (a[j] == 1) sum++;
    }
    ans = ans + min(sum, n / k - sum);
  }
  printf("%d\n", ans);
  return 0;
}
