solve (a:b:as) | a <= b = a : solve (b:as)
               | otherwise = b : solve (b:as)
solve (a:as) = [a]
solve [] = []

solveSub (a:b:as) | a <= b = a
                  | otherwise = b
solveSub (a:as) = a
solveSub [] = 0

main = do
    n <- readLn :: IO Int
    bn <- map read . words <$> getLine :: IO [Int]
    print $ sum $ (solveSub bn) : (solve bn)