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