#include <bits/stdc++.h>
using namespace std;
inline void getarrint1(vector<int>& a, int n, istream& in) {
  for (int i = 1; i <= n; i++) in >> a[i];
}
class Solution {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n, k;
    in >> n >> k;
    vector<int> v(n + 1);
    getarrint1(v, n, in);
    int ans = 0;
    for (int i = 1; i <= k; i++) {
      int o, t;
      o = t = 0;
      for (int j = 1; j <= n / k; j++) {
        int ind = (j - 1) * k + i;
        if (v[ind] == 1)
          o++;
        else
          t++;
      }
      ans += min(o, t);
    }
    out << ans << '\n';
  }
};
void solve(std::istream& in, std::ostream& out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in = cin;
  ostream& out = cout;
  solve(in, out);
  return 0;
}
