import java.util.Scanner;

public class Balls {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        int[] ballBoxes = new int[n];
        for (int i = 0; i < n; i++) {
            ballBoxes[i] = in.nextInt();
        }

        int price = 0;
        for (int i = n - 1; i > 0; i--) {
            int currentBox = ballBoxes[i];
            price += currentBox;
            for (int j = i; j >= 0; j--) {
                if (ballBoxes[j] == 0) {
                    break;
                }
                if (ballBoxes[j] != currentBox) {
                    ballBoxes[j]--;
                }
            }
        }
        System.out.println(price);
    }
}
