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