{-# LANGUAGE RecursiveDo        #-}
{-# LANGUAGE OverloadedStrings  #-}
{-# LANGUAGE NumericUnderscores #-}

import qualified Data.ByteString.Char8 as C8
import Data.List
import Data.Char

solve :: Int -> Int -> [Int] -> Int
solve d1 d2 [x, y   ] = d2
solve d1 d2 [x, y, z] = dn
  where a  = d1 + abs (z - x)
        b  = d2 + abs (z - y)
        dn = min a b
solve d1 d2 (x:y:z:h) = solve d2 dn (y:z:h)
  where a  = d1 + abs (z - x)
        b  = d2 + abs (z - y)
        dn = min a b

main :: IO ()
main = do
  _ <- getLine
  h@(h0:h1:hs) <- unfoldr (C8.readInt . C8.dropWhile isSpace) <$> C8.getLine
  print $ solve 0 (abs (h0 - h1)) h
