#include <bits/stdc++.h>
using namespace std;
template <class T>
T _abs(T n) {
  return (n < 0 ? -n : n);
}
template <class T>
T _max(T a, T b) {
  return (!(a < b) ? a : b);
}
template <class T>
T _min(T a, T b) {
  return (a < b ? a : b);
}
template <class T>
T sq(T x) {
  return x * x;
}
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
bool vis[2100][2100];
int dp[2100][2100];
int n, k, f[2100];
int dfs(int p, int lf) {
  if (p > 2010) return (lf == k) ? 0 : (p + 1);
  if (vis[p][lf]) return dp[p][lf];
  vis[p][lf] = 1;
  int t, r = 0;
  if (lf >= f[p]) {
    t = lf - f[p];
    if (!t) r = p;
  } else {
    t = f[p] - lf;
    r = p;
    r += (t / k) * p;
    t %= k;
    t = k - t;
  }
  if (t)
    dp[p][lf] = r + min(p + dfs(p + 1, k), dfs(p + 1, t));
  else
    dp[p][lf] = r + dfs(p + 1, k);
  return dp[p][lf];
}
int main() {
  int i, u;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> u;
    f[u - 1]++;
  }
  cout << 2 * dfs(0, k) << '\n';
  return 0;
}
