N = int(eval(input()))

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



ans = 0

st = "0"

while H!=[0]*N:

    for i in range(N):

        if H[i]>0:

            st = "+"

            H[i] -= 1

        elif st=="+" and H[i]==0:

            st = "0"

            ans += 1

    if st=="+":

        ans += 1

    st = "0"



print(ans)







# Python3 (3.4.3)

import sys

input = sys.stdin.readline



# -------------------------------------------------------------

# function

# -------------------------------------------------------------





# -------------------------------------------------------------

# main

# -------------------------------------------------------------

N = int(eval(input()))

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



ans = 0

x = [H]



while len(x) > 0:

    A = x.pop()

    minA = min(A)

    k = A.index(minA)

    for i in range(len(A)):

        A[i] -= minA

    ans += minA

    if A[0:k] != []:

        x.append(A[0:k])

    if A[k+1:] != []:

        x.append(A[k+1:])



print(ans)
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
st = "0"
while H != [0] * N:
    for i in range(N):
        if H[i] > 0:
            st = "+"
            H[i] -= 1
        elif st == "+" and H[i] == 0:
            st = "0"
            ans += 1
    if st == "+":
        ans += 1
    st = "0"
print(ans)

# Python3 (3.4.3)
import sys

input = sys.stdin.readline
# -------------------------------------------------------------
# function
# -------------------------------------------------------------
# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(eval(input()))
H = list(map(int, input().split()))
ans = 0
x = [H]
while len(x) > 0:
    A = x.pop()
    minA = min(A)
    k = A.index(minA)
    for i in range(len(A)):
        A[i] -= minA
    ans += minA
    if A[0:k] != []:
        x.append(A[0:k])
    if A[k + 1 :] != []:
        x.append(A[k + 1 :])
print(ans)

+# Python3 (3.4.3) +import sys + +input = sys.stdin.readline +# function +# main -st = "0" -while H != [0] * N: -    for i in range(N): -        if H[i] > 0: -            st = "+" -            H[i] -= 1 -        elif st == "+" and H[i] == 0: -            st = "0" -            ans += 1 -    if st == "+": -        ans += 1 -    st = "0" +x = [H] +while len(x) > 0: +    A = x.pop() +    minA = min(A) +    k = A.index(minA) +    for i in range(len(A)): +        A[i] -= minA +    ans += minA +    if A[0:k] != []: +        x.append(A[0:k]) +    if A[k + 1 :] != []: +        x.append(A[k + 1 :])