#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1.0);
const double EPS = 1E-9;
const int inf = (1e+9);
const int NMAX = 1e+4;
const int MOD = 1743;
int n, k;
int arr[101];
int main() {
  cin >> n >> k;
  for (int i = 0; i < (n); ++i) cin >> arr[i];
  int ans = 0;
  for (int i = 0; i < (k); ++i) {
    int c1 = 0, c2 = 0;
    for (int j = i; j < n; j += k) {
      if (arr[j] == 1) c1++;
      if (arr[j] == 2) c2++;
    }
    ans += (c1 + c2) - max(c1, c2);
  }
  cout << ans;
}
