#include <bits/stdc++.h>
using namespace std;
int a[110];
int num1[110];
int num2[110];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  int ct = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (a[i] == 1)
      num1[ct]++;
    else
      num2[ct]++;
    ct++;
    if (ct == k) ct %= k;
  }
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += min(num1[i], num2[i]);
  }
  printf("%d\n", ans);
  return 0;
}
