#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sc second

typedef long long ll;
const ll INF = 100000000007, DIM = 100007;

ll tt, a[DIM], n,res, c;
map<ll,ll> s;

void solve(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		s[a[i]]++;
	}
	for(auto u = s.rbegin(); u !=s.rend();++u){
		res+=max(0ll, (u->first-c)*u->second);
		c+=u->second;
	}
	cout<<res<<'\n';
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	tt=1;
	//cin>>tt;
	while(tt--)
		solve();
	return 0;
}