import Data.Array (Array, Ix, array, (!), range)
type IArr  = Array Int Integer

main = do
    n <- readLn :: IO Int
    hs <- map read . words <$> getLine :: IO [Integer]
    print $ solve n (genArray n hs) 0

memorize :: Ix a => (a -> b) -> (a, a) -> (a -> b)
memorize func rng = let memoArray = array rng [(i, func i) | i <- (range rng)]
                    in (!) memoArray

solve :: Int -> IArr -> Int -> Integer
solve n d = memorize (solve' n d) (0, n-1) where

solve' :: Int -> IArr -> Int -> Integer
solve' n d i
  | i == n-1  = 0
  | i == n-2  = abs $ d!i - d!(n-1)
  | otherwise = min a b where
      a = solve n d (i+1) + abs (d!i - d!(i+1))
      b = solve n d (i+2) + abs (d!i - d!(i+2))

genArray :: Int -> [Integer] -> IArr
genArray n xs = array (0, n-1) [x | x <- zip [0..n] xs]
