n = gets.to_i
h = gets.split.map(&:to_i)
ans = 0
while h.any?{|i|i != 0}
    i = 0
    while h[i] == 0
        i += 1
    end
    for j in i..n-1
        if h[j] != 0
            h[j] -= 1
        else
            break
        end
    end
    ans += 1
end
puts ans