n = gets
ar = gets.chomp.split(' ')
result = []

for i in 0..(n-1) do
  ins = n - i - 1
  if i == (n-1)
    result.push(ar[ins])
  else
    if ar[ins] > ar[ins-1]
      result.push(ar[ins])
    else
      result.push(ar[ins-1])
    end
  end
end

result.each do |n|
  a += n
end
puts a