let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.map f
let n = (read int) - 1
let bs' = reads int
let as' = Array.append [| Array.head bs' |] bs'
for i = n downto 1 do
    as'.[i-1] <- min as'.[i] as'.[i-1] 
printfn "%A" (Array.sum as')