n = int(input())
d = list(map(int, input().split()))
answer = 0
while sum(d) != 0:
    x = max(d)
    for i in range(d.index(x), n):
        if x == d[i]:
            d[i] -= 1
        else:
            break
    answer += 1
print(answer)
