#include <bits/stdc++.h>

using namespace std;

#define DIM 20007

long long n, a, res, box, p;

map<long long,int>m;
priority_queue<long long>pq;

int main(){

    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a;

        if(m[a]==0) pq.push(a);
        m[a]++;
    }

    while(pq.size()){
        box=pq.top();

        res+=max((long long)0,(box-p)*m[box]);
        p+=m[box];

        pq.pop();
    }

    cout << res << endl;
    return 0;
}
