#include
#include
using namespace std;
int main() {
unsigned int n;
cin >> n;
unsigned int chains[500000];
unsigned int free = 0;
for (int i = 0; i < n; i++) {
cin >> chains[i];
}
sort(chains, chains + n);
bool open = true;
unsigned int connections = 0;
unsigned int* cur = chains;
unsigned int needed = n - 1;
unsigned int have = 0;
unsigned int moves = 0;
while (open) {
have += *cur;
needed--;
moves += *cur;
if (have == needed) {
cout << moves << endl;
return 0;
} else if (have > needed) {
//UNDO LAST MOVE AND TEST
have -= *cur;
needed++;
moves -= *cur;
//cout << *cur << " " << needed << " " << moves << " " << have << endl;
moves += needed-have;
cout << moves << endl;
return 0;
}
cur++;
}
return 0;
}