#include <bits/stdc++.h>
using namespace std;
const int N = int(5e5) + 10, mod = int(1e9) + 7;
int n, a[N];
long long second;
int mx, mx2;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    if (a[i] >= mx) {
      mx2 = mx;
      mx = a[i];
    } else if (mx2 < a[i])
      mx2 = a[i];
    second += 2 * a[i];
    second -= min(a[i], a[i - 1]);
  }
  second = second - 2 * mx - mx2;
  printf("%lld", second);
  return 0;
}
