N = int(eval(input()))

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



cnt = 0

while True:

    allzero = True

    for i in range(N):

        if(h[i] != 0):

            allzero = False

    if allzero: break



    l = 0

    while h[l] == 0:l += 1

    r = l

    while r <N-1 and h[r+1]!=0:

        r +=1

    cnt += 1

    for i in range(l,r + 1,1):

        h[i] -=1

print(cnt)

#from statistics import median

#import collections

#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]

#from itertools import combinations # (string,3) 3回

#from collections import deque

#import collections.defaultdict

#import bisect

#

#    d = m - k[i] - k[j]

#    if kk[bisect.bisect_right(kk,d) - 1] == d:

#

#

#

# pythonで無理なときは、pypyでやると正解するかも！！

#

#



import sys

sys.setrecursionlimit(10000)

mod = 10**9 + 7



def readInts():

  return list(map(int,input().split()))

def main():

    n = int(eval(input()))

    H = readInts()

    allzero = False

    cnt = 0

    while True:

        for i in range(n):

            allzero = True

            if H[i] > 0:

                allzero = False

                left = i

                break

                # ここで左がわを決めておく

        #print(left)

        if allzero:

            print(cnt)

            exit()

        i = left

        right = left

        while i < n and H[i] > 0:

            right += 1

            i += 1

            if i >= n:

                break

        for j in range(left,right):

            #print(j)

            H[j] -=1

        #print(*H)

        cnt += 1



if __name__ == '__main__':

  main()

N = int(eval(input()))
h = list(map(int, input().split()))
cnt = 0
while True:
    allzero = True
    for i in range(N):
        if h[i] != 0:
            allzero = False
    if allzero:
        break
    l = 0
    while h[l] == 0:
        l += 1
    r = l
    while r < N - 1 and h[r + 1] != 0:
        r += 1
    cnt += 1
    for i in range(l, r + 1, 1):
        h[i] -= 1
print(cnt)

# from statistics import median
# import collections
# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
# from itertools import combinations # (string,3) 3回
# from collections import deque
# import collections.defaultdict
# import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
import sys

sys.setrecursionlimit(10000)
mod = 10**9 + 7


def readInts():
    return list(map(int, input().split()))


def main():
    n = int(eval(input()))
    H = readInts()
    allzero = False
    cnt = 0
    while True:
        for i in range(n):
            allzero = True
            if H[i] > 0:
                allzero = False
                left = i
                break
                # ここで左がわを決めておく
        # print(left)
        if allzero:
            print(cnt)
            exit()
        i = left
        right = left
        while i < n and H[i] > 0:
            right += 1
            i += 1
            if i >= n:
                break
        for j in range(left, right):
            # print(j)
            H[j] -= 1
        # print(*H)
        cnt += 1


if __name__ == "__main__":
    main()

-N = int(eval(input())) -h = list(map(int, input().split())) -cnt = 0 -while True: -    allzero = True -    for i in range(N): -        if h[i] != 0: -            allzero = False -    if allzero: -        break -    l = 0 -    while h[l] == 0: -        l += 1 -    r = l -    while r < N - 1 and h[r + 1] != 0: -        r += 1 -    cnt += 1 -    for i in range(l, r + 1, 1): -        h[i] -= 1 -print(cnt) +# from statistics import median +# import collections +# aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] +# from itertools import combinations # (string,3) 3回 +# from collections import deque +# import collections.defaultdict +# import bisect +# +#    d = m - k[i] - k[j] +#    if kk[bisect.bisect_right(kk,d) - 1] == d: +# +# +# +# pythonで無理なときは、pypyでやると正解するかも！！ +# +# +import sys + +sys.setrecursionlimit(10000) +mod = 10**9 + 7 + + +def readInts(): +    return list(map(int, input().split())) + + +def main(): +    n = int(eval(input())) +    H = readInts() +    allzero = False +    cnt = 0 +    while True: +        for i in range(n): +            allzero = True +            if H[i] > 0: +                allzero = False +                left = i +                break +                # ここで左がわを決めておく +        # print(left) +        if allzero: +            print(cnt) +            exit() +        i = left +        right = left +        while i < n and H[i] > 0: +            right += 1 +            i += 1 +            if i >= n: +                break +        for j in range(left, right): +            # print(j) +            H[j] -= 1 +        # print(*H) +        cnt += 1 + + +if __name__ == "__main__": +    main()