#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ll long long
#define ld long double
#define fi first
#define sc second
#define point pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define show(x) cerr << (#x) << " = " << x << '\n'
#define print(x) if (1) {cerr << (#x) << " = "; \
      for (auto it : x) cerr << it << ' '; cerr << '\n';}

using namespace std;
using namespace __gnu_pbds;

const int MAXN = 200064;
const int MAXT = 1e7 + 64;
const int ROOT = 1024;
const int MOD = 998244353;
const int LOG = 31;
const int INF = INT_MAX;
const ll MAX = LLONG_MAX;

signed main() {
      ios_base::sync_with_stdio(0);
      cin.tie(0);

      int n;
      cin >> n;

      map<int, int> mp;
      for (int i = 0, x; i < n; ++i)
            cin >> x, ++mp[x];

      vector<point> v;
      for (auto it : mp)
            v.push_back(it);

      ll ans = 0, of = 0;

      for (int i = v.size() - 1; i >= 0; --i)
            ans += max(0ll, (v[i].first - of) * v[i].second), of += v[i].second;
      cout << ans;
}
