main :: IO ()
main = do
  getLine
  hs <- map read . words <$> getLine
  print $ solve hs

solve :: [Int] -> Int
solve hs = head $ tail $ foldl f [0, 0, maxBound, head hs] hs
  where
    f [c_prev, c, h_prev, h] h_next 
      = [c, (c + dist h h_next) `min` (c_prev + dist h_prev h_next), h, h_next]

dist :: Int -> Int -> Int
dist h1 h2 = abs (h1 - h2)
