#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline int add(int a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline int mul(int a, int b) { return (a * 1ll * b) % 1000000007; }
inline int power(int a, int b) {
  int rt = 1;
  while (b > 0) {
    if (b & 1) rt = mul(rt, a);
    a = mul(a, a);
    b >>= 1;
  }
  return rt;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    int n, k;
    cin >> n >> k;
    int ar[n];
    for (int i = 0; i < n; i++) cin >> ar[i];
    int ans = 0;
    for (int i = 0; i < k; i++) {
      int a = 0, b = 0;
      for (int j = i; j < n; j += k) {
        if (ar[j] == 1)
          a++;
        else
          b++;
      }
      ans += min(a, b);
    }
    cout << ans << "\n";
  }
  return 0;
}
