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