#include <bits/stdc++.h>
using namespace std;
const int maxn = 300010;
const int mod = 100007;
const int N = 500 + 7;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1);
int n, m, cnt, ans, flag;
inline int read() {
  register int c = getchar(), fg = 1, sum = 0;
  while (c > '9' || c < '0') {
    if (c == '-') fg = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return fg * sum;
}
int num[123];
void init() {
  for (int i = 0; i < n; i++) num[i] = read();
}
void go() {
  ans = 0;
  int a = 0, b = 0;
  for (int i = 0; i < m; i++) {
    a = b = 0;
    for (int j = i; j < n; j += m)
      if (num[j] - 1)
        a++;
      else
        b++;
    ans += n / m - max(a, b);
  }
  printf("%d\n", ans);
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    init();
    go();
  }
}
