(L, N) = gets.split.map(&:to_i)
X = []
N.times do
  X << gets.to_i
end

$max = 0

def calc(x, current = 0, sum = 0)
  # left
  ccw = x.first - current
  ccw = L + ccw if ccw < 0
  lsum = sum + ccw
  lcurrent = current + ccw
  lcurrent = lcurrent - L if lcurrent >= L
  lx = x.dup
  lx.shift
  unless lx.size.zero?
    calc(lx, lcurrent, lsum)
  end

  # right
  cw = current - x.last
  cw = L + cw if cw < 0
  rsum = sum + cw
  rcurrent = current - cw
  rcurrent = L + rcurrent if rcurrent < 0
  rx = x.dup
  rx.pop
  unless rx.size.zero?
    calc(rx, rcurrent, rsum)
  end

  if $max < lsum
    $max = lsum
  end

  if $max < rsum
    $max = rsum
  end
end

calc(X, 0, 0)
puts $max