#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  scanf("%d", &(n));
  scanf("%d", &(k));
  int A[101];
  for (int(i) = 0; (i) < (n); (i)++) {
    scanf("%d", &(A[i]));
  }
  int x, y, ans = 0;
  for (int(i) = 0; (i) < (k); (i)++) {
    x = 0;
    y = 0;
    for (int(j) = 0; (j) < (n / k); (j)++) {
      if (A[j * k + i] == 2)
        y++;
      else
        x++;
    }
    ans += min(x, y);
  }
  cout << ans << endl;
  return 0;
}
