import Data.List
main :: IO ()
main = do
    _ <- getLine 
    h0:hs <- fmap (map read . words) getLine
    let (_, c_end, _, _) = foldl' step s0 hs 
        step (h1, c1, h2, c2) h = (h, c, h1, c1)
            where c = min (c1 + abs (h1 - h)) (c2 + abs (h2-h))
        s0 = (h0, 0, h0, 0)
    print (c_end :: Int)
        

    

