import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B
import Data.Char (isSpace)
import Data.Vector (Vector, (!), (//))
import qualified Data.Vector as V
import Data.Vector.Mutable (IOVector, STVector)
import qualified Data.Vector.Mutable as VM

main :: IO ()
main = do
  
  solve <$> readLn <*> f >>= print
  where
    f = readiv B.readInt <$> B.getLine

solve :: Int -> Vector Int -> Int
solve n hv = runST $ do
  h <- V.thaw hv
  cst <- VM.replicate n 0
  h0 <- VM.read h 0
  h1 <- VM.read h 1
  VM.write cst 1 (abs $ h1 - h0)
  forM_ [2 .. n-1] $ \i -> do
    hi_2 <- VM.read h (i - 2)
    hi_1 <- VM.read h (i - 1)
    hi_0 <- VM.read h i
    ci_2 <- VM.read cst (i - 2)
    ci_1 <- VM.read cst (i - 1)
    VM.write cst i (min (ci_2 + (abs $ hi_0 - hi_2)) (ci_1 + (abs $ hi_0 - hi_1)))
  VM.read cst (n - 1)

readiv :: Integral a =>  (ByteString -> Maybe (a, ByteString)) -> ByteString -> Vector a
readiv f = V.unfoldr $ \s -> do
  (n, s') <- f s
  return (n, B.dropWhile isSpace s')
