import itertools

import math

import fractions

import functools

import copy

n = int(eval(input()))

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



ans = 0

active = 0

for i in range(n):

    if h[i] <= active:

        active = h[i]

    else:

        ans += h[i] - active;    

        active = h[i]

print(ans)
def main():

    n = int(eval(input()))

    # n, m = map(int, input().split())

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

    # s = input()

    # h = [int(input()) for _ in range(n)]



    count = 0

    h.append(0)

    for j in range(max(h)):

        for i in range(n):

            if h[i] != 0 and h[i+1] == 0:

                count += 1

            if h[i] != 0:

                h[i] -= 1

    

    print(count)







if __name__ == '__main__':

    main()

import itertools
import math
import fractions
import functools
import copy

n = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
active = 0
for i in range(n):
    if h[i] <= active:
        active = h[i]
    else:
        ans += h[i] - active
        active = h[i]
print(ans)

def main():
    n = int(eval(input()))
    # n, m = map(int, input().split())
    h = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in range(n)]
    count = 0
    h.append(0)
    for j in range(max(h)):
        for i in range(n):
            if h[i] != 0 and h[i + 1] == 0:
                count += 1
            if h[i] != 0:
                h[i] -= 1
    print(count)


if __name__ == "__main__":
    main()

-import itertools -import math -import fractions -import functools -import copy +def main(): +    n = int(eval(input())) +    # n, m = map(int, input().split()) +    h = list(map(int, input().split())) +    # s = input() +    # h = [int(input()) for _ in range(n)] +    count = 0 +    h.append(0) +    for j in range(max(h)): +        for i in range(n): +            if h[i] != 0 and h[i + 1] == 0: +                count += 1 +            if h[i] != 0: +                h[i] -= 1 +    print(count) -n = int(eval(input())) -h = list(map(int, input().split())) -ans = 0 -active = 0 -for i in range(n): -    if h[i] <= active: -        active = h[i] -    else: -        ans += h[i] - active -        active = h[i] -print(ans) + +if __name__ == "__main__": +    main()