let iota n =
    let rec _iota n a =
        if n < 0 then a else _iota (n - 1) (n :: a) in
    _iota (n - 1) [];;


let max_route x l =
    let rec _max_route x y is_odd prev_route prev_y a =
        match x with
          [] -> a
        | (h::xs) ->
                match y with
                  [] -> 0
        | (now::ys) ->
                match is_odd with
                        | true ->
                                let route = prev_route + l - prev_y * 2 + h * 2 in
                                _max_route xs ys false route prev_y (max a route)
                        | _ ->
                                let route = prev_route + l - prev_y - now + h * 2 in
                                _max_route xs y true route now (max a route) in
    match x with
      [] -> 0
                        | (h::xs) ->
                                _max_route xs x true h h h;;




let () =
    let (l, n) = Scanf.scanf " %d %d" (fun l n -> (l, n)) in
    let x = List.rev_map (fun i -> Scanf.scanf " %d" (fun x -> x)) (iota n) in
    let x_rev = List.rev_map (fun y -> l - y) x in
    print_int (max (max_route x l) (max_route x_rev l));
    print_newline();;
