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

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