let n = int (stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.map int
Array.foldBack (fun z (li, back) -> if z <= back then (z :: li, z) else (back :: li, z)) a ([], 100000) |> fun x -> List.sum (fst x) + a.[0] |> printfn "%d"