# -*- coding: utf-8 -*-



n = int(eval(input()))

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



if not len(h_list) == n :

    raise RuntimeError("Mismatch Length.")



count = 0

while True:

    h_max = max(h_list)



    if h_max == 0:

        break



    isMax_list = [h == h_max for h in h_list]



    for i, isMax in enumerate(isMax_list):

        if isMax:

            h_list[i] -= 1

            if i == 0 or not isMax_list[i-1]:

                count += 1



print(count)

N = int(eval(input()))

H = [0] + list(map(int, input().split()))

ans = 0

for i in range(N):

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

print(ans)

# -*- coding: utf-8 -*-
n = int(eval(input()))
h_list = list(map(int, input().split()))
if not len(h_list) == n:
    raise RuntimeError("Mismatch Length.")
count = 0
while True:
    h_max = max(h_list)
    if h_max == 0:
        break
    isMax_list = [h == h_max for h in h_list]
    for i, isMax in enumerate(isMax_list):
        if isMax:
            h_list[i] -= 1
            if i == 0 or not isMax_list[i - 1]:
                count += 1
print(count)

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

-# -*- coding: utf-8 -*- -n = int(eval(input())) -h_list = list(map(int, input().split())) -if not len(h_list) == n: -    raise RuntimeError("Mismatch Length.") -count = 0 -while True: -    h_max = max(h_list) -    if h_max == 0: -        break -    isMax_list = [h == h_max for h in h_list] -    for i, isMax in enumerate(isMax_list): -        if isMax: -            h_list[i] -= 1 -            if i == 0 or not isMax_list[i - 1]: -                count += 1 -print(count) +N = int(eval(input())) +H = [0] + list(map(int, input().split())) +ans = 0 +for i in range(N): +    ans += max(H[i + 1] - H[i], 0) +print(ans)