from functools import reduce



N = int(eval(input()))

h = [int(s) for s in input().split()]



prev = 0

count = 0



for i in range(N):

    count += h[i] - prev if h[i] > prev else 0

    prev = h[i]



print(count)

def grand_garden(N: int, H: list) -> int:

    before = 0

    op = 0

    for h in H:

        if before < h:

            op += h - before

        before = h



    return op





if __name__ == "__main__":

    N = int(eval(input()))

    H = [int(s) for s in input().split()]



    ans = grand_garden(N, H)

    print(ans)

from functools import reduce

N = int(eval(input()))
h = [int(s) for s in input().split()]
prev = 0
count = 0
for i in range(N):
    count += h[i] - prev if h[i] > prev else 0
    prev = h[i]
print(count)

def grand_garden(N: int, H: list) -> int:
    before = 0
    op = 0
    for h in H:
        if before < h:
            op += h - before
        before = h
    return op


if __name__ == "__main__":
    N = int(eval(input()))
    H = [int(s) for s in input().split()]
    ans = grand_garden(N, H)
    print(ans)

-from functools import reduce +def grand_garden(N: int, H: list) -> int: +    before = 0 +    op = 0 +    for h in H: +        if before < h: +            op += h - before +        before = h +    return op -N = int(eval(input())) -h = [int(s) for s in input().split()] -prev = 0 -count = 0 -for i in range(N): -    count += h[i] - prev if h[i] > prev else 0 -    prev = h[i] -print(count) + +if __name__ == "__main__": +    N = int(eval(input())) +    H = [int(s) for s in input().split()] +    ans = grand_garden(N, H) +    print(ans)