module Main where
import qualified Data.Vector as V

main = do
  _ <- getLine
  x0 : xs0 <- map read . words <$> getLine

  print (go x0 xs0 x0 :: Int)

go prev (x:xs) acc = go x xs $! min prev x + acc
go prev [] acc = prev + acc
