#include <stdio.h>
#include <stdlib.h>

int main(void)
{
	long i, n, k, j;
	long prc = 0;

	scanf("%ld", &n);
	long *a = malloc(n*sizeof(long));
	for (i = 0; i < n; i++) {
		scanf("%ld", &k);
		a[i] = k;
	}

	for (i = n-1; i > 0 && a[i] > 0; i--) {
		prc += a[i];
		for (j = i-1; j > 0 && a[j] > 0; j--)
			if (a[j] != a[i])
				a[j]--;
	}

	printf("%ld\n", prc);

	free(a);

	return 0;
}
