#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define PII pair<int,int>
#define f first
#define s second
#define PB push_back
#define MIN(a,b) a=min(a,b)
#define MAX(a,b) a=max(a,b)
#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()
#define V vector
#define PDI pair<double, int> 
#define Pll pair<ll,ll>
const int N=2e3;
const ll mod=1e9+7;
const double eps=1e-9;
const double PI=acos(-1);
#define INF 2000000000

int main(){
	int n;
	cin>>n;
	V<int> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(rALL(a));
	ll ans=0;
	int ln=0,d;
	for(int i=0;i<n;i++){
		if(a[i]!=ln)
			if(a[i]<=i)
				break;
			else 
				d=i,
				ln=a[i];
		ans+=a[i]-d;
	}
	cout<<ans;
}