n = gets.to_i
b_array = gets.chomp.split(" ").map(&:to_i)

pre_a = b_array[0]
ret = pre_a
(0...(n-1)).each do |i|
    if i < n-2 && b_array[i] > b_array[i+1]
        pre_a = b_array[i+1]
    elsif pre_a < b_array[i]
        pre_a = b_array[i]
    end
    ret += pre_a
end

puts ret