N=int(eval(input()))

H=list(map(int, input().split()))

import numpy as np



H=np.array(H)

ans=0

for i in range(H.max()):

    #print(H)

    count=0

    now=(H[0]==0)

    if not now:

        count+=1

    for j in range(1,N):

        if now:

            if H[j]!=0:

                count+=1

        

        now=(H[j]==0)

    ans+=count

    #print(count)

    H[H>0]-=1

print(ans)



import numpy as np

N=int(eval(input()))



H=list(map(int, input().split()))

H=np.array(H)

MAX=H.max()



ans=0

for i in range(MAX):

    nowzero=True

    count=0

    for j in range(N):

        if nowzero:

            if H[j]>0:

                nowzero=False

                count+=1

        else:

            if H[j]<=0:

                nowzero=True

    ans+=count

    #print(H)

    H-=1



#print(H)

print(ans)
N = int(eval(input()))
H = list(map(int, input().split()))
import numpy as np

H = np.array(H)
ans = 0
for i in range(H.max()):
    # print(H)
    count = 0
    now = H[0] == 0
    if not now:
        count += 1
    for j in range(1, N):
        if now:
            if H[j] != 0:
                count += 1
        now = H[j] == 0
    ans += count
    # print(count)
    H[H > 0] -= 1
print(ans)

import numpy as np

N = int(eval(input()))
H = list(map(int, input().split()))
H = np.array(H)
MAX = H.max()
ans = 0
for i in range(MAX):
    nowzero = True
    count = 0
    for j in range(N):
        if nowzero:
            if H[j] > 0:
                nowzero = False
                count += 1
        else:
            if H[j] <= 0:
                nowzero = True
    ans += count
    # print(H)
    H -= 1
# print(H)
print(ans)

+import numpy as np + -import numpy as np - +MAX = H.max() -for i in range(H.max()): +for i in range(MAX): +    nowzero = True +    count = 0 +    for j in range(N): +        if nowzero: +            if H[j] > 0: +                nowzero = False +                count += 1 +        else: +            if H[j] <= 0: +                nowzero = True +    ans += count -    count = 0 -    now = H[0] == 0 -    if not now: -        count += 1 -    for j in range(1, N): -        if now: -            if H[j] != 0: -                count += 1 -        now = H[j] == 0 -    ans += count -    # print(count) -    H[H > 0] -= 1 +    H -= 1 +# print(H)