#include <bits/stdc++.h>
int main() {
  int a[105][105], i, j, min, sum = 0, n, k, c[5];
  scanf("%d%d", &n, &k);
  for (i = 1; i <= n / k; i++)
    for (j = 1; j <= k; j++) scanf("%d", &a[i][j]);
  for (i = 1; i <= k; i++) {
    min = 0;
    memset(c, 0, sizeof(c));
    for (j = 1; j <= n / k; j++) {
      if (a[j][i] == 1)
        c[a[j][i]]++;
      else
        c[a[j][i]]++;
    }
    if (c[1] < c[2])
      min = c[1];
    else
      min = c[2];
    sum += min;
  }
  printf("%d\n", sum);
  return 0;
}
