-- Try AtCoder
-- author: Leonardone @ NEETSDKASU

import Data.List (tails)

main = print . solve . map read . tail . words =<< getContents

solve xs = ans where
    ans =  sum . map hoge $ tails xs
    hoge [] = 0
    hoge (z:zs) = fst $ foldl f (z, z) zs
    f (sm, mn) t = let u = min mn t in (sm + u, u)