const insert = (circle, person) => {
  let max = 0
  let index = 0

  circle.forEach((v, i) => {
    const prev = i - 1 === -1 ? circle.length - 1 : i - 1
    const comfortableness = Math.min(circle[prev], circle[i])

    if (comfortableness > max ) {
      max = comfortableness
      index = i
    }
  })

  circle.splice(index, 0, person)

  return max
}

const main = async () => {
  const input = require('fs').readFileSync('/dev/stdin', 'UTF-8').trim()
  const [hString, aStrings] = input.split('\n')
  const h = Number(hString)
  const as = aStrings.split(' ').map(Number)

  as.sort((a, b) => b - a)
  const circle = []
  
  const comfortableness = as.reduce((a, person) => a + insert(circle, person), 0)
  
  console.log(comfortableness)
}

main()