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