inputs = readlines

n = inputs[0].to_i
as = Array.new(n)
bs = inputs[1].split(' ').map(&:to_i)

(0..n-2).each do |i|
  if as[i]
    as[i] = bs[i] if as[i] > bs[i]
  else
    as[i] = bs[i]
  end

  if as[i + 1]
    as[i + 1] = bs[i] if as[i + 1] > bs[i]
  else
    as[i + 1] = bs[i]
  end
end

p as
puts as.inject(:+)

