#include <bits/stdc++.h>
using namespace std;
const int NMax = 101;
const int INF = int(1e9);
const int sizeTree = 262145;
const double eps = 1e-9;
const double PI = 3.141592653589793238462;
const int MOD = int(1e9);
int n, k, ans = 0;
int a[NMax];
int main() {
  scanf("%i%i", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%i", &a[i]);
  for (int i = 1; i <= k; i++) {
    int cnt = 0;
    for (int j = 1; j <= n / k; j++)
      if (a[(j - 1) * k + i] == 1) cnt++;
    ans += min(cnt, n / k - cnt);
  }
  printf("%i", ans);
  return 0;
}
