{-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char (ord, isDigit)
import Data.Bits
import Data.Int
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import System.IO (stdin)

foreign import ccall "getchar_unlocked" cGetChar :: IO Char

-- Assume that input has non-digit symbol at the end.
readIONat :: (Bits a, Integral a) => IO a
readIONat = do
  let reader ch = fromIntegral $ ord ch - ord '0'

  digit0 <- fix
    (\(!f) (!_) -> do
      ch <- cGetChar
      if isDigit ch then return ch else f ch
    )
    ' '
  flip fix (return $ reader digit0) $ \(!f) (!acc) -> do
    s <- cGetChar
    if not (isDigit s)
      then acc
      else do
        a <- acc
        let a' = shiftL a 1 + shiftL a 3 + reader s
        a' `seq` f (return a')

solve :: Int -> VU.Vector Int16 -> Int32
solve !n !hs = fst dp
 where
  -- dp[i]: minimal cost of moving from 1st to i-th place
  dp :: (Int32, Int32)
  dp = VU.foldl'
    (\(!dp1, !dp2) (!i, !v) -> if i == 0
      then (0, dp1)
      else if i == 1
        then (dp1 + abs (fromIntegral $ v - hs VU.! 0), dp1)
        else
          ( min (dp1 + abs (fromIntegral $ v - hs VU.! (i - 1)))
                (dp2 + abs (fromIntegral $ v - hs VU.! (i - 2)))
          , dp1
          )
    )
    (-1, -1)
    (VU.indexed hs)

main = do
  n <- readIONat
  let
    hs =
      VU.unfoldrN n (\_ -> Just (accursedUnutterablePerformIO readIONat, ())) ()
  print $ solve n hs
