# 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 collections



def main():

    n = int(eval(input()))

    h = input_list()

    count = 0

    while True:

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

            break

        count += 1

        f = False

        for i, v in enumerate(h):

            if v == 0:

                if f:

                    break

            if v > 0:

                h[i] -= 1

                f = True

    print(count)





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 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 collections


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


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


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


if __name__ == "__main__":
    main()

-# import re -import bisect -import math -import fractions -import collections -import itertools -from functools import reduce -    h = list(input_list()) +    h = input_list() -        flag = False +        f = False -            if v != 0: -                flag = True +            if v == 0: +                if f: +                    break +            if v > 0: -            else: -                if flag: -                    break +                f = True - - -def minus(numbers): -    for i, n in enumerate(numbers): -        if n == 0: -            break -        numbers[i] -= 1 -    return numbers