N = int(eval(input()))

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

ans = 0

def zero_spliter(L):

    cnt = 1

    for x in L:

        if x == 0:

            cnt += 1

    M = [[] for _ in range(cnt)]

    i = 0

    for x in L:

        if x != 0:

            M[i].append(x)

        else:

            i += 1

    for x in M:

        if x != []:

            yield x

ans = 0

def counter(L):

    global ans

    if L == []:

        pass

    if 0 in L:

        l = list(zero_spliter(L))

        for x in l:

            counter(x)

    else:

        M = [x-1 for x in L]

        ans += 1

        counter(M)

counter(L)

print(ans)

N = int(eval(input()))

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



def count(L):

    if len(L) == 1:

        return L[0]

    if L == []:

        return 0

    if 0 in L:

        i = L.index(0)

        return count(L[:i]) + count(L[i+1:])

    else:

        m = min(L)

        L = list([x-m for x in L])

        return m + count(L) 

print((count(L)))

N = int(eval(input()))
L = list(map(int, input().split()))
ans = 0


def zero_spliter(L):
    cnt = 1
    for x in L:
        if x == 0:
            cnt += 1
    M = [[] for _ in range(cnt)]
    i = 0
    for x in L:
        if x != 0:
            M[i].append(x)
        else:
            i += 1
    for x in M:
        if x != []:
            yield x


ans = 0


def counter(L):
    global ans
    if L == []:
        pass
    if 0 in L:
        l = list(zero_spliter(L))
        for x in l:
            counter(x)
    else:
        M = [x - 1 for x in L]
        ans += 1
        counter(M)


counter(L)
print(ans)

N = int(eval(input()))
L = list(map(int, input().split()))


def count(L):
    if len(L) == 1:
        return L[0]
    if L == []:
        return 0
    if 0 in L:
        i = L.index(0)
        return count(L[:i]) + count(L[i + 1 :])
    else:
        m = min(L)
        L = list([x - m for x in L])
        return m + count(L)


print((count(L)))

-ans = 0 -def zero_spliter(L): -    cnt = 1 -    for x in L: -        if x == 0: -            cnt += 1 -    M = [[] for _ in range(cnt)] -    i = 0 -    for x in L: -        if x != 0: -            M[i].append(x) -        else: -            i += 1 -    for x in M: -        if x != []: -            yield x +def count(L): +    if len(L) == 1: +        return L[0] +    if L == []: +        return 0 +    if 0 in L: +        i = L.index(0) +        return count(L[:i]) + count(L[i + 1 :]) +    else: +        m = min(L) +        L = list([x - m for x in L]) +        return m + count(L) -ans = 0 - - -def counter(L): -    global ans -    if L == []: -        pass -    if 0 in L: -        l = list(zero_spliter(L)) -        for x in l: -            counter(x) -    else: -        M = [x - 1 for x in L] -        ans += 1 -        counter(M) - - -counter(L) -print(ans) +print((count(L)))