let solve =
    let rec sol xs =
        match xs with
        | [] -> 0
        | [_] -> 0
        | x :: y :: zs -> min x y + sol zs
    in List.sort >> sol

let () =
    let _ = stdin.ReadLine()
    let xs = stdin.ReadLine().Split(' ') |> Array.map int |> List.ofArray
    in solve xs |> printfn "%d"
