#include <bits/stdc++.h>
using namespace std;
int ar[105][105];
int cnt[105];
int main() {
  int n, k, a = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n / k; i++) {
    for (int j = 1; j <= k; j++) {
      scanf("%d", &ar[i][j]);
      if (ar[i][j] == 1) cnt[j]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= k; i++) ans += min(cnt[i], n / k - cnt[i]);
  printf("%d\n", ans);
  return 0;
}
