#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int freq[K][3];
  for (int i = 0; i < K; i++) {
    freq[i][1] = freq[i][2] = 0;
  }
  for (int i = 0; i < N; i++) {
    int temp;
    cin >> temp;
    freq[i % K][temp]++;
  }
  int count = 0;
  for (int i = 0; i < K; i++) {
    count += min(freq[i][1], freq[i][2]);
  }
  cout << count << endl;
  return 0;
}
