input = STDIN.read.split("\n").map{|l| l.split(" ").map{|a| a.to_i}}
first = input.shift

L = first[0]
N = first[1]
points = input.map{|r| r[0]}
current = 0
COSTS = []

def burn(trees, cost, current_pt)
  if trees.length === 0 
    COSTS.push(cost)
    return
  end

  dtf = nil
  f_trees = trees.clone
  tf = f_trees.shift
  if tf > current_pt
    dtf = tf - current_pt
  else
    dtf = tf + (L - current_pt)
  end
  burn(f_trees, cost + dtf, tf)

  dtb = nil
  b_trees = trees.clone
  tb = b_trees.pop
  if tb < current_pt
    dtb = current_pt - tb
  else
    dtb = current_pt + (L - tb)
  end
  burn(b_trees, cost + dtb, tb)
end

burn(points, 0, 0)
puts COSTS.max