import Data.Array

makeDpTable :: (Array Int Int) -> Int -> Int -> [Int] -> [Int]
makeDpTable a b c ans
 | b == 0    = makeDpTable a (b + 1) c (0:ans)
 | b == 1    = makeDpTable a (b + 1) c (((ans !! 0) + abs((a ! 1) - (a ! 0))):ans)
 | b == c    = ans
 | otherwise = makeDpTable a (b + 1) c newAns
  where newVal = min ((ans !! 0) + abs((a ! b) - (a ! (b - 1)))) ((ans !! 1) + abs((a ! b) - (a ! (b - 2))))
        newAns = newVal:ans
 
main = do
 n <- read <$> getLine :: IO Int
 hList <- map read . words <$> getLine :: IO [Int]
 print $ head $ makeDpTable (listArray (0, n - 1) hList) 0 n []