#include <bits/stdc++.h>
const double PI = acos(-0);
const int mod = 1000007;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int NEXT[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
using namespace std;
int a[101][3];
int main() {
  int n, k, ans, x;
  scanf("%d%d", &n, &k);
  int q = 0;
  memset((a), (0), (sizeof(a)));
  while (n--) {
    scanf("%d", &x);
    if (x == 1) {
      a[q][1]++;
    }
    if (x == 2) {
      a[q][2]++;
    }
    q++;
    q = q % k;
  }
  ans = 0;
  for (int i = 0; i < k; i++) {
    if (a[i][1] < a[i][2]) {
      ans += a[i][1];
    } else {
      ans += a[i][2];
    }
  }
  printf("%d\n", ans);
}
