#include <bits/stdc++.h>
using namespace std;
int v[1000000], ant[1000000], nxt[1000000];
int n;
int ja[1000000];
bool cmp(int a, int b) { return v[a] < v[b]; }
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) nxt[i] = i + 1;
  for (int i = 1; i < n; i++) ant[i] = i - 1;
  vector<int> u;
  for (int i = 1; i < n - 1; i++) u.push_back(i);
  sort((u).begin(), (u).end(), cmp);
  for (int i = 0; i < u.size(); i++) {
    int x = u[i];
    if (v[ant[x]] >= v[x] && v[nxt[x]] >= v[x]) {
      int a = ant[x], b = nxt[x];
      ant[b] = a, nxt[a] = b;
      ja[u[i]] = 1;
      ans += min(v[a], v[b]);
    }
  }
  reverse((u).begin(), (u).end());
  vector<int> val;
  for (int i = 0; i < u.size(); i++) {
    int x = u[i];
    if (ja[u[i]]) continue;
    val.push_back(v[u[i]]);
  }
  val.push_back(v[0]), val.push_back(v[n - 1]);
  sort((val).begin(), (val).end());
  for (int i = 0; i < val.size() - 2; i++) ans += val[i];
  cout << ans << endl;
  return 0;
}
