n = int(input())
l = list(map(int, input().split()));
c = 0;
while n > 0 and l[-1] != 0:
    n = n - 1;
    c = c + l[-1];
    for i in range(n):
        if l[i] != l[-1] and l[i] != 0:
            l[i] = l[i] - 1;
    l.pop();
print(c);