#include <bits/stdc++.h>

using namespace std;

#define endl "\n"
#define pb push_back
#define mp make_pair
#define in insert
#define INF 1e9
#define eps 0.0000000001
#define fi first
#define se second
#define y1 yy
#define speedup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;

//---------------------------------------|

const int DIM=1e5+7;

ll n,m,x,y,t,res,pr,mpr;
ll a[DIM];
priority_queue<ll> p;

//---------------------------------------|

int main()
{
    speedup;

    cin >> n;

    for (int i=1;i<=n;i++)
    {
        cin >> x;
        p.push(x);
    }

    m=0;
    mpr=0;
    pr=p.top();
    while(p.size()!=0)
    {
        t=p.top();
        p.pop();

        if (t!=pr)
        {
            m+=mpr;
            mpr=0;
        }
        pr=t;

        res+=max(0LL,t-m);
        mpr++;
    }

    cout << res << endl;

    return 0;
}
