#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl '\n'
const int N = 2e5+7;
void solve(){
    int n;
    cin>>n;
    map<int,int> M;
    for(int i = 1;i<=n;i+=1){
        int pos;
        cin>>pos;
        M[pos] += 1;
    }

    ll res = 0;
    ll pre = 0;
    for(auto it = M.rbegin();it!=M.rend();it++){
        int i = it->first;
        int qnt = it->second;
        if (i-pre<=0){
            break;
        }
        res += ll(i-pre)*qnt;
        pre += qnt;
    }
    cout<<res<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
