#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  int** array = new int*[n / k];
  for (int i = 0; i < n / k; i++) {
    array[i] = new int[k];
  }
  for (int i = 0; i < n / k; i++) {
    for (int j = 0; j < k; j++) {
      cin >> array[i][j];
    }
  }
  long long ans = 0;
  for (int j = 0; j < k; j++) {
    int one = 0;
    int two = 0;
    for (int i = 0; i < n / k; i++) {
      if (array[i][j] == 1) {
        one++;
      } else if (array[i][j] == 2) {
        two++;
      }
    }
    if (one > two) {
      ans += two;
    } else {
      ans += one;
    }
  }
  cout << ans << endl;
}
