#include <bits/stdc++.h>
using namespace std;
inline void reads(string& x) {
  char kk[200];
  scanf("%s", kk);
  x = kk;
}
int n, k, p[200];
void solve() {
  scanf("%d%d", &n, &k);
  for (int i = 0, val; i < n; i++) {
    scanf("%d", &val);
    p[i % k] += val == 1;
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += min(p[i], n / k - p[i]);
  }
  printf("%d\n", ans);
}
int main() {
  ios_base::sync_with_stdio(0);
  int t = 1;
  for (int caso = 1; caso <= t; caso++) {
    solve();
  }
}
