{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Data.Int
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B

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

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  hs <- VU.unfoldrN n readInt <$> B.getLine
  print $ solve n hs
