#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  if (N <= 4) {
    vector<int> A(N);
    int M = N - 2;
    int sum = 0;
    for (int i = 0; i < N; i++) {
      cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    for (int i = N; i > 1; i--) {
      sum += A[i];
    }
    cout << sum - A[0] << endl;
  } else {
    vector<int> A(N);
    int M = N - 2;
    int sum = 0;
    for (int i = 0; i < N; i++) {
      cin >> A.at(i);
    }
    sort(A.begin(), A.end());
    for (int i = N; i > 1; i--) {
      sum += A[i];
    }
    cout << sum - A[0] + A[M] << endl;
  }
}
