

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static int n;

    static boolean check0(int[] mas){
        for (int a: mas) {
            if(a!=0) return false;
        }
        return true;
    }


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

        int[] mas = new int[n];
        int money = 0;

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


        for(int i=n-1; i>=0; i--){
            money+=mas[i];
            for (int j = 0; j < i; j++) {
                if(mas[j]!=mas[i] && mas[j]!=0) mas[j]--;
            }

//            for (int k = 0; k < n; k++) {
//                System.out.print(mas[k] + " ");
//            }
//            System.out.println();

            mas[i]=0;

            if(check0(mas)==true){
                System.out.println(money);
                System.exit(0);
            }
        }
        System.out.println(money);

    }
}
