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 = f i
        where 
            f i 
                | x == i = 0
                | x - 1 == i  = abs((a!i) - a!(i+1))
                | otherwise = min ((ll ! (i + 1)) + abs((a!i) - a!(i+1))) 
                    ((ll ! (i + 2)) + abs((a!(i)) - a!(i+2)))
            ll = listArray (1, x) $ map f [1..x]