N = gets.to_i
B = gets.split.map(&:to_i)
A = Array.new(N)
A[-1] = B[-1]
A[-2] = B[-1]
[*0..N-3].reverse.each do |i|
    A[i] = B[i]
    if B[i] < A[i+1] then
        A[i+1] = B[i]
    end
end
puts A.inject(:+)