#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <map>

#define pii pair<int, int>
#define S second
#define F first
#define pb push_back

using namespace std;

typedef long long ll;

void solve (){
  ll n, k = 0, rez = 0;
  cin >> n;
  vector <int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] = -v[i];
  }
  sort(v.begin(), v.end());
  v.push_back(1);
  
  ll t = 0;
  while (t < n) {  
    ll p = t;
    while (v[p] == v[p+1]) {p++;}
    rez += ((p-t+1)*(max(0LL, abs(v[t])-k)));
    k += (p-t+1);
    t = p+1;
  }

  cout << rez;
  return;
}

int main(){
  solve();

  return 0;
}
