n = int(eval(input()))

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

r = i = 0

while max(h) != 0:

    if h[i] == 0:

        i += 1

    else:

        r += 1

        while i < n and h[i] > 0:

            h[i] -= 1

            i += 1

        i = 0

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

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

r = i = 0

while sum(h) != 0:

    if h[i] == 0:

        i += 1

    else:

        r += 1

        while i < n and h[i] > 0:

            h[i] -= 1

            i += 1

        i = 0

print(r)
n = int(eval(input()))
h = [int(i) for i in input().split()]
r = i = 0
while max(h) != 0:
    if h[i] == 0:
        i += 1
    else:
        r += 1
        while i < n and h[i] > 0:
            h[i] -= 1
            i += 1
        i = 0
print(r)

n = int(eval(input()))
h = [int(i) for i in input().split()]
r = i = 0
while sum(h) != 0:
    if h[i] == 0:
        i += 1
    else:
        r += 1
        while i < n and h[i] > 0:
            h[i] -= 1
            i += 1
        i = 0
print(r)

-while max(h) != 0: +while sum(h) != 0: