import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Data.Char

a#b = abs$a-b

main = B.interact$B.pack.show.f.V.unfoldr(B.readInt.B.dropWhile isSpace)
f :: V.Vector Int -> Int
f v= q n hv
  where
    n = v V.! 0
    hv = V.slice 1 n v
q n hv = av V.! (n - 1)
  where
    av = V.generate n m
    m 0 = 0
    m 1 = (hv V.! 0) # (hv V.! 1)
    m i = min ((av V.! (i-2)) + ((hv V.! (i-2)) # (hv V.! i))) ((av V.! (i-1)) + ((hv V.! (i-1)) # (hv V.! i)))
