main = do
 getLine
 a <- map read . words <$> getLine
 print(solve a (front a))
 
fmin :: Integer -> Integer -> Integer
fmin a b = if a <= b then a else b

fabs :: Integer -> Integer
fabs x = if x < 0 then -x else x

front :: [Integer] -> Integer
front (x:xs) = x
 
solve :: [Integer] -> Integer -> Integer
solve [] x = 0
solve [x] y = fabs (x-y)
solve (x:y:xs) z = fmin (fabs(z-x)+solve (y:xs) x) (fabs(z-y)+solve (xs) y)