n = input()
m = input()
k = m.split(" ")
a = 0
boo = True
ch = False
for i in k:
    k[k.index(i)] = int(i)
c = max(k)
last = k.index(c)
while max(k) !=0:
    for j in k:
        c = max(k)

        
        
        if j == c and boo == True:
            boo = False
            last  = k.index(j)
            
            k[k.index(j)] = j-1
            j = j-1
            ch = True
            if c!= max(k):
                c = max(k)
            continue
        if (k.index(j)-last==1) and (j == k[last]+1)and (ch == True):
            last = k.index(j)
            k[k.index(j)] = j-1
            j = j-1
            
            ch = True
            if c!= max(k):
                c = max(k)
        elif ch == True:
            ch = False
            a = a+1
            boo = True
            last = k.index(max(k))
        if ch == True and k.index(j)== len(k)-1:
            ch = False
            a = a+1
            boo = True
            last = k.index(max(k))
        print(k)
        
print(a)
