#define _CRT_SECURE_NO_WARNINGS
//#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <cstdlib>
#include <algorithm>
#include <cmath>
//#include <numeric>
//#include <string> 
#include <vector>
//#include <array>
//#include <unordered_map>
#include <map>
//#include <queue>
//#include <set>
//#include <stack>
//#include <string>

using u = unsigned;
using u64 = uint64_t;

constexpr u N = (u)1e5;

int main() {
    u n;
    scanf("%u", &n);
    std::map<u, u, std::greater<u>> m;
    for(u i = 0, v; i < n; i++) scanf("%u", &v), m[v]++;
    u offset = 0;
    u64 cost = 0;
    for(auto [pos, count] : m) {
        if(pos <= offset) break;
        cost += (pos - offset) * count;
        offset += count;
    }
    printf("%llu", cost);
}