import fractions

import sys

from functools import reduce

import math



input = sys.stdin.readline





def main():

    n = int(eval(input()))

    h = input_list()

    count = 0

    while list(set(h)) != [0]:

        count += 1

        flag = False

        for i, v in enumerate(h):

            if v != 0:

                flag = True

                h[i] -= 1

            else:

                if flag:

                    break

    print(count)



def divide_two(n):

    c = 0

    while True:

        if c >= 2:

            break

        if n % 2 != 0:

            break

        n //= 2

        c += 1

    return c



def get_camulative(l):

    import itertools

    # 累積和

    return [0] + list(itertools.accumulate(l))



def combinations_count(n, r):

    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))





def input_list():

    return list(map(int, input().split()))





def input_list_str():

    return list(map(str, input().split()))





def lcm_base(x, y):

    return (x * y) // fractions.gcd(x, y)





def lcm_list(numbers):

    return reduce(lcm_base, numbers, 1)





def gcd(*numbers):

    return reduce(fractions.gcd, numbers)





def gcd_list(numbers):

    return reduce(fractions.gcd, numbers)





if __name__ == "__main__":

    main()

# import sys

# input = sys.stdin.readline

# import re

import collections

import bisect

import math

import fractions

import collections

import itertools

from functools import reduce



def main():

    n = int(eval(input()))

    h = list(input_list())

    count = 0

    while True:

        if list(set(h)) == [0]:

            break

        flag = False

        count += 1

        for i, v in enumerate(h):

            if v != 0:

                flag = True

                h[i] -= 1

            else:

                if flag:

                    break

    print(count)



def minus(numbers):

    for i, n in enumerate(numbers):

        if n == 0:

            break

        numbers[i] -= 1

    return numbers





def input_list():

    return list(map(int, input().split()))





def input_list_str():

    return list(map(str, input().split()))





if __name__ == '__main__':

    main()



import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n = int(eval(input()))
    h = input_list()
    count = 0
    while list(set(h)) != [0]:
        count += 1
        flag = False
        for i, v in enumerate(h):
            if v != 0:
                flag = True
                h[i] -= 1
            else:
                if flag:
                    break
    print(count)


def divide_two(n):
    c = 0
    while True:
        if c >= 2:
            break
        if n % 2 != 0:
            break
        n //= 2
        c += 1
    return c


def get_camulative(l):
    import itertools

    # 累積和
    return [0] + list(itertools.accumulate(l))


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()

# import sys
# input = sys.stdin.readline
# import re
import collections
import bisect
import math
import fractions
import collections
import itertools
from functools import reduce


def main():
    n = int(eval(input()))
    h = list(input_list())
    count = 0
    while True:
        if list(set(h)) == [0]:
            break
        flag = False
        count += 1
        for i, v in enumerate(h):
            if v != 0:
                flag = True
                h[i] -= 1
            else:
                if flag:
                    break
    print(count)


def minus(numbers):
    for i, n in enumerate(numbers):
        if n == 0:
            break
        numbers[i] -= 1
    return numbers


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()

+# import sys +# input = sys.stdin.readline +# import re +import collections +import bisect +import math -import sys +import collections +import itertools -import math - -input = sys.stdin.readline -    h = input_list() +    h = list(input_list()) -    while list(set(h)) != [0]: +    while True: +        if list(set(h)) == [0]: +            break +        flag = False -        flag = False -def divide_two(n): -    c = 0 -    while True: -        if c >= 2: +def minus(numbers): +    for i, n in enumerate(numbers): +        if n == 0: -        if n % 2 != 0: -            break -        n //= 2 -        c += 1 -    return c - - -def get_camulative(l): -    import itertools - -    # 累積和 -    return [0] + list(itertools.accumulate(l)) - - -def combinations_count(n, r): -    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) +        numbers[i] -= 1 +    return numbers -def lcm_base(x, y): -    return (x * y) // fractions.gcd(x, y) - - -def lcm_list(numbers): -    return reduce(lcm_base, numbers, 1) - - -def gcd(*numbers): -    return reduce(fractions.gcd, numbers) - - -def gcd_list(numbers): -    return reduce(fractions.gcd, numbers) - -