let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x k =
    try k @@ Hashtbl.find dp x with
    | Not_found ->
        f get x @@ fun y ->
          Hashtbl.add dp x y; k y in get

let () = Scanf.scanf "%d %d\n" @@ fun len n ->
  let xs = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun x -> x in
  let dp = memoize (2 * n * n) @@ fun dp (l, r, b) k ->
    if r <= l then k 0
    else if b then
      dp (l + 1, r, true) @@ fun a1 ->
        dp (l + 1, r, false) @@ fun a2 ->
          k @@ max (xs.(l + 1) - xs.(l) + a1) (len - xs.(r) + xs.(l) + a2)
    else
      dp (l, r - 1, false) @@ fun a1 ->
        dp (l, r - 1, true) @@ fun a2 ->
          k @@ max (xs.(r) - xs.(r - 1) + a1) (len - xs.(r) + xs.(l) + a2) in
  Printf.printf "%d\n" @@ 
    dp (0, n - 1, true) @@ fun a1 ->
      dp (0, n - 1, false) @@ fun a2 ->
        max (xs.(0) + a1) (len - xs.(n - 1) + a2)

