#include <bits/stdc++.h>
using namespace std;
int a[111];
int c[3];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    c[1] = c[2] = 0;
    for (int j = i; j <= n; j += k) {
      c[a[j]]++;
    }
    ans += min(c[1], c[2]);
  }
  cout << ans << "\n";
  cin >> n;
  return 0;
}
