n = int(input())
m=list(map(int,input().split()))
ans=0
per=0
while len(m)!=0:
    per1=len(m)
    ans=ans+m[per1-1]
    per=m[per1-1]
    m.pop(per1-1)
    per1=len(m)
    per2=len(m)
    g=0
    while g<per2:
        if m[g]==0:
            m.pop(g)
            per2=per2-1
        g=g+1
    per1=len(m)
    for i in range(per1):
        if m[i]!=per:
            m[i]=m[i]-1
print(ans)