
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val p = readLine.trim.split(' ').map(_.toInt)
  var min = Int.MaxValue
  for (r ← 0 to p.head){
    val arr = p.clone()
    var sum = r
    arr(0) -= r
    for (i ← arr.indices){
      if (arr(i) > 0){
        sum += arr(i)
        if (i + 1 < arr.length) {
          sum += arr(i)
          arr(i + 1) -= arr(i)
        }
      }
    }
    if (sum < min) min = sum
  }
  println(
    min
  )
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
/*


 */
