#include <bits/stdc++.h>

#define INF 1000000005
#define INFL 1000000000000000005ll
#define EPS 1e-6
#define pb push_back
#define pause system("pause")
#define exit exit(0)
#define endl '\n'

using namespace std;
using ull = unsigned long long;
using ll = long long;

typedef pair<ll, ll> pii;
const int N = 200005, MOD = 998244353;

int n, a[N];
map<int, int> cnt;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		++cnt[-a[i]];
	}

	ll d = 0, ans = 0;
	for (auto x : cnt) {
		ll pos = -x.first - d;
		ll cnt = x.second;
		if (pos < 1) {
			break;
		}

		ans += pos * cnt, d += cnt;
	}

	cout << ans << endl;
	//pause;
	return 0;
}
