#include <bits/stdc++.h>
using namespace std;
const int maxN = 1E2 + 10;
const int mod = 1E9 + 7;
int a[maxN], b[maxN];
int32_t main() {
  int n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) b[i % k] += a[i] - 1;
  for (int i = 0; i < n; ++i) sum += min(b[i], (n / k) - b[i]);
  cout << sum << "\n";
  return 0;
}
