#include <bits/stdc++.h>
using namespace std;
const long long N = 5e4 + 5;
const long long mod = 1e9 + 7;
int32_t main() {
  long long n, k;
  cin >> n >> k;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long tot = 0, sz = 0;
  vector<long long> v[N];
  for (long long i = 0; i < n; i++) {
    v[sz].push_back(arr[i]);
    tot++;
    if (tot == k) {
      sz++;
      tot = 0;
    }
  }
  long long ans = 0;
  for (long long i = 0; i < k; i++) {
    map<long long, long long> mp;
    for (long long j = 0; j < sz; j++) {
      mp[v[j][i]]++;
    }
    long long mx = 0;
    for (auto v : mp) {
      mx = max(mx, v.second);
    }
    ans += (sz - mx);
  }
  cout << ans;
}
