#include <bits/stdc++.h>
using namespace std;
int a[101], k, i, n, check[101][101], j = 0, kil1, kil2, ans;
int main() {
  cin >> n >> k;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= k; i++) {
    kil1 = 0;
    kil2 = 0;
    for (j = i; j <= n; j += k) {
      if (a[j] == 1)
        kil1++;
      else
        kil2++;
    }
    ans += min(kil1, kil2);
  }
  cout << ans << endl;
  return 0;
}
