import Data.Array

main = do
    n <- readLn
    getLine >>= putStrLn.show.answer n.listArray (1,n).map read.words

answer :: Int -> Array Int Int -> Int
answer n = (!1).dp n

dp n costs =
    let ans = array (1,n) $ (n,0) : (n-1, n#(n-1)) : [(k,min(ans!(k+1)+k#(k+1)) (ans!(k+2)+k#(k+2))) | k <- [1..n-2]]
    in ans where
        a#b = abs $ (costs!a) - (costs!b)