# ABC116 C - Grand Garden

import numpy as np

n = int(eval(input()))

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

l = [9]*n

t = 0

x = 0

if n == 1:

    print((h[0]))

    exit()



while max(h) > 0:

    if x != 0:

        for i in range(n):

            h[i] -= 1



    for i in range(n):

        if h[i] > 0:

            l[i] = 1

        else:

            l[i] = 0



    for i in range(n-1):

        if i == 0 and l[0] == 1:

            t += 1

        if l[i+1]-l[i] == 1:

            t += 1

    x += 1



print(t)
n=int(eval(input()))

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

from itertools import groupby

ans=0

for i in range(101):

  c=[0]*n

  for j in range(n):

    if h[j]>0:c[j]=1

  gr=groupby(c)

  for k,v in gr:

    if k>0:ans+=1

  for j in range(n):

    if h[j]>0:h[j]-=1

print(ans)





# ABC116 C - Grand Garden
import numpy as np

n = int(eval(input()))
h = list(map(int, input().split()))
l = [9] * n
t = 0
x = 0
if n == 1:
    print((h[0]))
    exit()
while max(h) > 0:
    if x != 0:
        for i in range(n):
            h[i] -= 1
    for i in range(n):
        if h[i] > 0:
            l[i] = 1
        else:
            l[i] = 0
    for i in range(n - 1):
        if i == 0 and l[0] == 1:
            t += 1
        if l[i + 1] - l[i] == 1:
            t += 1
    x += 1
print(t)

n = int(eval(input()))
h = list(map(int, input().split()))
from itertools import groupby

ans = 0
for i in range(101):
    c = [0] * n
    for j in range(n):
        if h[j] > 0:
            c[j] = 1
    gr = groupby(c)
    for k, v in gr:
        if k > 0:
            ans += 1
    for j in range(n):
        if h[j] > 0:
            h[j] -= 1
print(ans)

-# ABC116 C - Grand Garden -import numpy as np - -l = [9] * n -t = 0 -x = 0 -if n == 1: -    print((h[0])) -    exit() -while max(h) > 0: -    if x != 0: -        for i in range(n): -            h[i] -= 1 -    for i in range(n): -        if h[i] > 0: -            l[i] = 1 -        else: -            l[i] = 0 -    for i in range(n - 1): -        if i == 0 and l[0] == 1: -            t += 1 -        if l[i + 1] - l[i] == 1: -            t += 1 -    x += 1 -print(t) +from itertools import groupby + +ans = 0 +for i in range(101): +    c = [0] * n +    for j in range(n): +        if h[j] > 0: +            c[j] = 1 +    gr = groupby(c) +    for k, v in gr: +        if k > 0: +            ans += 1 +    for j in range(n): +        if h[j] > 0: +            h[j] -= 1 +print(ans)