#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define mp make_pair
#define pb push_back

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

constexpr int INF = (int)1e18;
constexpr int N = (int)2e5 + 111;
constexpr int md = (int)998244353;

void solve(){
    int n;
    cin >> n;

    map<int,int> cnt;
    set<int> st;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        cnt[a]++;
        st.insert(a);
    }
    vector<int> v(st.begin(),st.end());

    int ans = 0;
    int c = 0;
    reverse(v.begin(),v.end());
    for(int i = 0; i < v.size(); i++){
        if(v[i] - c <= 0)
            break;
        ans += cnt[v[i]] * (v[i] - c);
        c += cnt[v[i]];
    }

    cout << ans << "\n";

    return;
}

signed main(){
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int tests = 1;
//    cin >> tests;
    for(int test = 1; test <= tests; test++){
        solve();
    }
    return 0;
}
/**
make VUDOI great again.

**/
