N = gets.to_i
p = gets.split.map &:to_i

p((p.first + 1).times.map{|i|
  q = p.dup
  sum = i
  q[0] -= i
  until q.size == 1
    sum += [0, q[0]].max * 2
    q[1] -= [0, q[0]].max
    q.shift
  end
  sum + [0, q[0]].max
}.min)