#include <bits/stdc++.h>
using namespace std;
vector<int> arr;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    arr.push_back(x);
  }
  int ans = 0;
  int max_cnt = n / k;
  for (int i = 0; i < k; i++) {
    int cnt = 0;
    for (int j = 0; j < n; j += k) {
      if (arr[j + i] == 1) {
        cnt++;
      }
    }
    ans += min(cnt, max_cnt - cnt);
  }
  printf("%d\n", ans);
}
