let () =
  let k, n = Scanf.scanf "%d %d\n" @@ fun a b -> a, b in
  let arr = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d in
  let brr = Array.make n 0 in
  for i = 0 to n-1 do
    print_int i; print_newline ();
    if i = 0 then brr.(n-1) <- abs (arr.(n-1) - arr.(i))
    else brr.(i-1) <- abs (arr.(i) - arr.(i-1))
  done;
  let ans = Array.fold_left
      (fun (m, s) x -> if m < x then (x, s+m) else (m, x+s)) (0, 0) brr in
  print_int (snd ans)