import math
import sys

def seqs(ns, k):
    s = 0
    lst = False
    for n in ns:
        cur = n >= k
        if cur and not lst:
            s = s + 1;
        lst = cur
    return s

kv = int(input())
ns =[int(n) for n in input().split()]
s = 0
for k in range(max(ns)):
    s = s + seqs(ns, k + 1)
print(s)
