main = do
	_ <- getLine
	xs <- map read.words <$> getLine :: IO [Int]
	putStrLn.show.dp $ reverse xs

to h1 h2 = abs $ h1 - h2

dp [] = 0
dp [x1] = 0
dp [x1,x2] = x1 `to` x2
dp (x1:x2:x3:xs) = min (x1 `to` x2 + dp (x2:x3:xs) ) (x1 `to` x3 + dp (x3:xs))