#include <bits/stdc++.h>
int main(int argc, char* argv[]) {
  int N, D;
  std::cin >> N >> D;
  std::vector<int> A;
  A.resize(N);
  for (auto& a : A) {
    std::cin >> a;
  }
  auto prev_front = A.front(), prev_back = A.back();
  std::sort(A.begin(), A.end());
  auto result = 2 * std::accumulate(A.begin(), A.end(), 0LL) + D * (N - 1) -
                A[N - 1] - A[N - 2];
  if (prev_front == A[N - 1]) {
    prev_front = 0;
  } else if (prev_back == A[N - 1]) {
    prev_back = 0;
  } else {
    result += std::min(A[N - 1], D);
  }
  if (prev_front == A[N - 2]) {
    prev_front = 0;
  } else if (prev_back == A[N - 2]) {
    prev_back = 0;
  } else {
    result += std::min(A[N - 2], D);
  }
  result -= prev_front + prev_back;
  std::cout << result;
  return 0;
}
