import io.StdIn._

object Main extends App {
  val n   = readInt()
  val seq = readLine().split(" ").map(_.toInt).toSeq

  require(2 <= n && n <= 100)
  require(seq.forall(_ <= 100000))

  println(
    seq.zipWithIndex
      .foldLeft(Seq.empty[Int])((s, a) => seq.lift(a._2 - 1).map(b => s.appended(b.min(a._1))).getOrElse(Seq(a._1)))
      .sum + seq.last
  )
}
