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