N = int(eval(input()))

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



ans = 0



while True:

    if not sum(h):

        break

    for l in range(N):

        if h[l]:

            break

    for r in range(l,N):

        if not h[r]:

            r -= 1

            break

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

        h[i] -= 1

    ans += 1



print(ans)

N = int(eval(input()))

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



ans = h[0]



for i in range(N-1):

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



print(ans)





N = int(eval(input()))
h = list(map(int, input().split()))
ans = 0
while True:
    if not sum(h):
        break
    for l in range(N):
        if h[l]:
            break
    for r in range(l, N):
        if not h[r]:
            r -= 1
            break
    for i in range(l, r + 1):
        h[i] -= 1
    ans += 1
print(ans)

N = int(eval(input()))
h = list(map(int, input().split()))
ans = h[0]
for i in range(N - 1):
    ans += max(0, h[i + 1] - h[i])
print(ans)

-ans = 0 -while True: -    if not sum(h): -        break -    for l in range(N): -        if h[l]: -            break -    for r in range(l, N): -        if not h[r]: -            r -= 1 -            break -    for i in range(l, r + 1): -        h[i] -= 1 -    ans += 1 +ans = h[0] +for i in range(N - 1): +    ans += max(0, h[i + 1] - h[i])