{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Applicative
import Data.Char
import Control.Monad.ST

solve :: VU.Vector Int -> Int
solve hs =
  runST $ do
    table <- VUM.new (l+1)
    VUM.write table 0 0
    forM_ [1..l-1] $ \i -> 
      if i==1 then
        VUM.write table i (h i 1)
      else do
        a1 <- VUM.read table (i-1)
        a2 <- VUM.read table (i-2)
        VUM.write table i $ min (a1 + h i 1) (a2 + h i 2)
    VUM.read table (l-1) 
  where
    l = VU.length hs
    h x n = abs $ (hs VU.! x) - (hs VU.! (x-n)) 

main = do
  n <- readLn :: IO Int
  (hs :: VU.Vector Int) <- VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve hs