#include <bits/stdc++.h>
int const inf = 1 << 29;
int const maxn = 200;
int f[maxn][3];
int a[maxn];
int n, k;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    std::cin >> a[i];
    f[i][1] = f[i][2] = inf;
  }
  f[n - k][1] = f[n - k][2] = 0;
  for (int i = n - k + 1; i <= n; i++) {
    int c1 = 0;
    for (int j = i; j >= 1; j -= k) c1 += a[j] == 2;
    f[i][1] = std::min(f[i][1], std::min(f[i - 1][1], f[i - 1][2]) + c1);
    int c2 = 0;
    for (int j = i; j >= 1; j -= k) c2 += a[j] == 1;
    f[i][2] = std::min(f[i][2], std::min(f[i - 1][1], f[i - 1][2]) + c2);
  }
  std::cout << std::min(f[n][1], f[n][2]) << "\n";
}
