n = int(eval(input()))

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

h.insert(0, 0)

h.append(0)

cnt = 0

while True:

    s = -1

    e = -1

    m_n = 10 ** 10

    for i in range(1, n + 2):

        if h[i] != 0 and h[i-1] == 0:

            s = i

            m_n = min(m_n, h[i])

            for j in range(i + 1, n + 2):

                if h[j] == 0 and h[j - 1] != 0:

                    e = j - 1

                    break

                else:

                    m_n = min(m_n, h[j])

    if s == -1 and e == -1:

        print(cnt)

        exit()

    else:

        cnt += m_n

        for i in range(s, e + 1):

            h[i] -= m_n



def slove():

    import sys

    input = sys.stdin.readline

    n = int(input().rstrip('\n'))

    h = list(map(int, input().rstrip('\n').split()))

    l = 0

    cnt = 0

    for i in range(n):

        if l < h[i]:

            cnt += h[i] - l

        l = h[i]

    print(cnt)





if __name__ == '__main__':

    slove()

n = int(eval(input()))
h = list(map(int, input().split()))
h.insert(0, 0)
h.append(0)
cnt = 0
while True:
    s = -1
    e = -1
    m_n = 10**10
    for i in range(1, n + 2):
        if h[i] != 0 and h[i - 1] == 0:
            s = i
            m_n = min(m_n, h[i])
            for j in range(i + 1, n + 2):
                if h[j] == 0 and h[j - 1] != 0:
                    e = j - 1
                    break
                else:
                    m_n = min(m_n, h[j])
    if s == -1 and e == -1:
        print(cnt)
        exit()
    else:
        cnt += m_n
        for i in range(s, e + 1):
            h[i] -= m_n

def slove():
    import sys

    input = sys.stdin.readline
    n = int(input().rstrip("\n"))
    h = list(map(int, input().rstrip("\n").split()))
    l = 0
    cnt = 0
    for i in range(n):
        if l < h[i]:
            cnt += h[i] - l
        l = h[i]
    print(cnt)


if __name__ == "__main__":
    slove()

-n = int(eval(input())) -h = list(map(int, input().split())) -h.insert(0, 0) -h.append(0) -cnt = 0 -while True: -    s = -1 -    e = -1 -    m_n = 10**10 -    for i in range(1, n + 2): -        if h[i] != 0 and h[i - 1] == 0: -            s = i -            m_n = min(m_n, h[i]) -            for j in range(i + 1, n + 2): -                if h[j] == 0 and h[j - 1] != 0: -                    e = j - 1 -                    break -                else: -                    m_n = min(m_n, h[j]) -    if s == -1 and e == -1: -        print(cnt) -        exit() -    else: -        cnt += m_n -        for i in range(s, e + 1): -            h[i] -= m_n +def slove(): +    import sys + +    input = sys.stdin.readline +    n = int(input().rstrip("\n")) +    h = list(map(int, input().rstrip("\n").split())) +    l = 0 +    cnt = 0 +    for i in range(n): +        if l < h[i]: +            cnt += h[i] - l +        l = h[i] +    print(cnt) + + +if __name__ == "__main__": +    slove()