#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  std ::ios_base ::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  vector<vector<int> > v;
  for (int j = 0; j < n / k; ++j) {
    vector<int> a(k);
    for (int i = 0; i < k; ++i) {
      cin >> a[i];
    }
    v.push_back(a);
  }
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    int ct1 = 0;
    int ct2 = 0;
    for (int j = 0; j < v.size(); ++j) {
      if (v[j][i] == 1)
        ct1++;
      else
        ct2++;
    }
    ans += min(ct1, ct2);
  }
  cout << ans << endl;
}
