#include <bits/stdc++.h>
using namespace std;
int mat[200][200];
int main() {
  int n, k, ma = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n / k; ++i)
    for (int j = 1; j <= k; ++j) scanf("%d", &mat[i][j]);
  for (int j = 1; j <= k; ++j) {
    int nr1 = 0, nr2 = 0;
    for (int i = 1; i <= n / k; ++i)
      if (mat[i][j] == 1)
        nr1++;
      else
        nr2++;
    if (nr1 > nr2)
      ma += nr2;
    else
      ma += nr1;
  }
  printf("%d", ma);
  return 0;
}
