fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var b = readLine()!!.split(" ").map { it.toInt()}.toMutableList()

    var list = mutableListOf<Int>()
    for (i in 0 until n)list.add(-1)
    var p = -1
    for (i in 0 until n - 1){
        for (j in 0 until n-1){
            if (b[j] == b.min()) {
                p = j
                break
            }
        }

        if (list.get(p) == -1)list.set(p, b[p])
        if (list.get(p+1) == -1)list.set(p+1, b[p])
        b[p] = 1000000
    }
    println(list.sum())
}