#include <bits/stdc++.h>
using namespace std;
const int MXN = 500100;
const int MXPW = 30;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const int mod = 1000000007;
int a[MXN];
int main() {
  int n;
  scanf("%d", &n);
  long long mx = 0, mx2 = 0;
  long long s = 0, mns = 0;
  for (int i = (0); i < (n); i++) {
    scanf("%d", &a[i]);
    if (i) mns += min(a[i], a[i - 1]);
    s += a[i];
    if (a[i] > mx)
      mx2 = mx, mx = a[i];
    else if (a[i] > mx2)
      mx2 = a[i];
  }
  cout << 2 * s - 2 * mx - mx2 - mns;
}
