N =int(eval(input()))

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



min = []

max = []

ans =0

while l !=[0]*N:

    ans += 1

    s =False

    for i,j in enumerate(l):

        if s:

            if j == 0:

                break

        if j !=0:

            s =True

            l[i]-=1

print(ans)

def f(l):

    sta = True

    for i,j in enumerate(l):

        if sta:

            if j!=0:

                sta=False

                l[i]-=1

        else:

            if j==0:

                break

            else:

                l[i]-=1

    return l







N =int(eval(input()))

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

m = 0

while h != [0]*N:

    h =f(h)

    m += 1

print(m)
N = int(eval(input()))
l = [int(i) for i in input().split()]
min = []
max = []
ans = 0
while l != [0] * N:
    ans += 1
    s = False
    for i, j in enumerate(l):
        if s:
            if j == 0:
                break
        if j != 0:
            s = True
            l[i] -= 1
print(ans)

def f(l):
    sta = True
    for i, j in enumerate(l):
        if sta:
            if j != 0:
                sta = False
                l[i] -= 1
        else:
            if j == 0:
                break
            else:
                l[i] -= 1
    return l


N = int(eval(input()))
h = [int(i) for i in input().split()]
m = 0
while h != [0] * N:
    h = f(h)
    m += 1
print(m)

-N = int(eval(input())) -l = [int(i) for i in input().split()] -min = [] -max = [] -ans = 0 -while l != [0] * N: -    ans += 1 -    s = False +def f(l): +    sta = True -        if s: +        if sta: +            if j != 0: +                sta = False +                l[i] -= 1 +        else: -        if j != 0: -            s = True -            l[i] -= 1 -print(ans) +            else: +                l[i] -= 1 +    return l + + +N = int(eval(input())) +h = [int(i) for i in input().split()] +m = 0 +while h != [0] * N: +    h = f(h) +    m += 1 +print(m)