#include <bits/stdc++.h>
using namespace std;
int N, K, res = 0;
int Num2[107];
int main() {
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; ++i) {
    int A;
    scanf("%d", &A);
    if (!(A % 2)) ++Num2[i % K];
  }
  int pr = N / K;
  for (int i = 0; i < K; ++i) res += min(Num2[i], pr - Num2[i]);
  printf("%d", res);
}
