#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k, cant;
  cin >> n >> k;
  cant = n / k;
  long long v[cant][k];
  for (long long i = 0; i < (long long)cant; i++)
    for (long long j = 0; j < (long long)k; j++) {
      cin >> v[i][j];
    }
  int t1 = 0, t2 = 0, t3 = 0;
  for (int i = 0; i < k; i++) {
    int cont = 0;
    for (int r = 0; r < cant; r++) {
      if (v[r][i] == 1) {
        cont++;
      }
    }
    t1 += min(cont, cant - cont);
  }
  cout << t1 << endl;
  return 0;
}
