import Data.Array((!), listArray)
main = interact $ show.helper.(map read).words

helper (x:xs) = fonk x a 1 
            where a = listArray (1, x) xs

fonk x a i
    | x == i = 0
    | x - 1 == i  = abs((a!i) - a!(i+1))
    | otherwise = min (((fonk x a) (i + 1)) + abs((a!i) - a!(i+1))) (((fonk x a) (i + 2)) + abs((a!(i)) - a!(i+2)))
