#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2000005;
const int MAXM = 200005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
int a[105], pos[105][2];
int main() {
  ios::sync_with_stdio(0);
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    pos[i % m == 0 ? m : i % m][a[i] - 1]++;
  }
  for (int i = 1; i <= m; i++) ans += min(pos[i][0], pos[i][1]);
  cout << ans << "\n";
  return 0;
}
