#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include<stack>
int main() {

	int n;
	std::cin >> n;
	std::vector<int> v;
	v.resize(n);
	for (int i = 0; i < n; i++)
	{
		std::cin >> v[i];
	}
	unsigned long long sum = 0;
	while (true)
	{
		int num = *(v.end() - 1);
		sum += num;
		v.pop_back();
		for (int i = 0; i < v.size(); i++)
		{
			if(v[i]!=num)
				v[i]--;
			if (v[i] == 0)
				v.erase(v.begin());
		}
		if (v.size() == 0)break;
	}
	std::cout << sum;


}