import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  n <- readInt
  bs <- readInts
  print $ g bs

g :: [Int] -> Int
g bb@(b:bs) = h 0 bb bs
  where
    h acc [b] [] = acc + b
    h acc (c:cs) (d:ds) = h (acc + (min c d)) cs ds
