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