n = gets.chomp.to_i
t_b = gets.chomp
b = t_b.split(' ').map{|v| v.to_i}

a = Array.new(n, 0)

b.each_with_index do |v, i|
  if i >= 1 && v > a[i]
    a[i+1] = v
  else
    a[i] = v
    a[i+1] = v
  end
end

result = 0
a.each do |v|
  result += v
end
p result