#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, n, k;
  cin >> n >> k;
  int ara[n];
  for (i = 0; i < n; i++) {
    cin >> ara[i];
  }
  int x = 0, s = 0;
  while (x < k) {
    int c_1 = 0, c_2 = 0;
    for (i = x; i < n; i += k) {
      if (ara[i] == 1)
        c_1++;
      else
        c_2++;
    }
    if (c_1 < c_2)
      s = s + c_1;
    else
      s = s + c_2;
    x++;
  }
  cout << s;
}
