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