#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n / k; i++) {
    for (int j = 0; j < k; j++) {
      cin >> a[i][j];
    }
  }
  int one = 0, two = 0, cnt = 0;
  for (int j = 0; j < k; j++) {
    one = 0, two = 0;
    for (int i = 0; i < n / k; i++) {
      if (a[i][j] == 1)
        one++;
      else
        two++;
    }
    if (one == 0 || two == 0)
      continue;
    else {
      cnt += min(one, two);
    }
  }
  cout << cnt;
}
