let rec solve (cost1, cost2) (h1, h2) hs =
    match hs with
    | h :: hs' ->
            let m = min (cost1 + abs (h - h1)) (cost2 + abs (h - h2)) in
            solve (cost2, m) (h2, h) hs'
    | [] -> cost2

let () =
    let _ = read_line () in
    let h =
        read_line ()
        |> Str.split (Str.regexp " ")
        |> List.map int_of_string
    in
    match h with
    | h1 :: h2 :: hs ->
            print_int (solve (0, abs (h2 - h1)) (h1, h2) hs);
            print_newline ()
    | _ -> ()
