import Data.Array
import Data.Array.ST
import Control.Monad
import Control.Monad.ST

gen_dp_tbl::Array Int Int ->Int->Array Int Int
gen_dp_tbl ar n = runSTArray $ do
  tbl<-newArray_ (1,n)
  writeArray tbl 1 0
  writeArray tbl 2 (abs (ar!1 - ar!2))
  forM_ [3..n] (\ i -> do
                      v<-readArray tbl (i-1)
                      w<-readArray tbl (i-2)
                      let next = min (v + abs (ar!i - ar!(i-1))) (w + abs (ar!i - ar!(i-2)))
                      writeArray tbl i next)
  return tbl

solver::[Int]->Int->Int
solver ls n = (gen_dp_tbl (listArray (1,n) ls) n)!n

main::IO()
main = do
   n<-(return.read)=<<getLine
   ls<-(return.(map read).words)=<<getLine
   print (solver ls n)