#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int arr[n];
  for (int i = 0; i < n; i++) cin >> arr[i];
  int c = 0;
  for (int i = 0; i < m; i++) {
    int o = 0, t = 0;
    for (int j = i; j < n; j += m) {
      if (arr[j] == 1)
        o++;
      else
        t++;
    }
    c += min(o, t);
  }
  cout << c;
  return 0;
}
