#include <cstdio>
#include <cmath>
#include <fstream>

using namespace std;

int main()
{
    ifstream cin("conquest.in");
    ofstream cout("conquest.out");
    int n, x, s = 2e9;
    long long t = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        s = min(s, x), t += s; 
    }
    cout << t - s;
}