#include <iostream>
#include <algorithm>
#include <stack>

using namespace std;

stack<int> a; int last = 0, uge = 0, potratili = 0;
int pred, aaaa, minuss = 1;

void pristrii() {
	pred = a.top();
	a.pop();
	if (a.size() != 0) {
		if (pred - minuss > 0) {
			potratili += (pred - minuss);
		}
		uge += 1;
	}
}

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

	int n, sum = 0, in;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> in;
		sum += in;
		a.push(in);
	}
	for (uge; uge < sum; uge) {
		pristrii();
		if (a.size() == 0) {
			break;
		}
	}
	cout << potratili << '\n';
}