N = int(input())
arr = list(map(int, input().split(' ')))

if N==1:
    print(N)
else:
    k = 0

    def find_longest_sub(array):
        big = max(arr)
        big_inds = []
        for i in range(N):
            if arr[i]==big:
                big_inds.append(i)
        long_len = [1, big_inds[0]]
        leng = [0, 0]
        made = False
        i = 0
        while i < len(big_inds):
            if not made:
                leng = [1, big_inds[i]]
                made = True
            if i+1<len(big_inds) and big_inds[i+1]==big_inds[i]+1:
                leng[0] += 1
            else:
                if leng[0] > long_len[0]:
                    long_len = leng
                made = False
                leng = [0, 0]
            i += 1
        return [long_len[0], long_len[1]]

    while sum(arr)>0:
        [sub_len, begin] = find_longest_sub(arr)
        for i in range(begin, begin+sub_len):
            arr[i] -= 1
        k += 1
    
    print(k)    
