N = int(eval(input()))

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



ans = 0



while max(h):

    mx = max(h)

    on = False



    for i in range(N):

        if h[i] == mx:

            h[i] -= 1

            if not on:

                ans += 1

            on = True

        else:

            on = False



print(ans)

def main():

    N, *h = list(map(int, open(0).read().split()))

    ans = h[0]

    for i in range(N - 1):

        ans += max(h[i + 1] - h[i], 0)

    print(ans)

    return





main()

N = int(eval(input()))
h = [int(i) for i in input().split()]
ans = 0
while max(h):
    mx = max(h)
    on = False
    for i in range(N):
        if h[i] == mx:
            h[i] -= 1
            if not on:
                ans += 1
            on = True
        else:
            on = False
print(ans)

def main():
    N, *h = list(map(int, open(0).read().split()))
    ans = h[0]
    for i in range(N - 1):
        ans += max(h[i + 1] - h[i], 0)
    print(ans)
    return


main()

-N = int(eval(input())) -h = [int(i) for i in input().split()] -ans = 0 -while max(h): -    mx = max(h) -    on = False -    for i in range(N): -        if h[i] == mx: -            h[i] -= 1 -            if not on: -                ans += 1 -            on = True -        else: -            on = False -print(ans) +def main(): +    N, *h = list(map(int, open(0).read().split())) +    ans = h[0] +    for i in range(N - 1): +        ans += max(h[i + 1] - h[i], 0) +    print(ans) +    return + + +main()