import qualified Data.ByteString.Char8 as B
import Data.Char
import Data.List

import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

a#b = abs$a-b

main = B.interact$B.pack.show.g.unfoldr(B.readInt.B.dropWhile isSpace)

g (n:h1:h2:hr)=runST $ do
    dp <- newListArray (1,n) (0:h2#h1:repeat 0)::ST s (STUArray s Int Int)
    forM_ (zip [3..n] (tails (h1:h2:hr))) $ \(i,a:b:c:_) -> do
        c1 <- (+ c#a) <$> readArray dp (i-2)
        c2 <- (+ c#b) <$> readArray dp (i-1)
        writeArray dp i (min c1 c2)
    readArray dp n
    where
        hv = listArray (1,n) (h1:h2:hr)