l, n = gets.split.map(&:to_i)
x = n.times.map { |n| gets.to_i }
# l, n = [10, 6]
# x = [1,2,3,6,7,9]

steps = 0
current = 0

x1 = x.dup

until x1.empty?
  xi, step = [
    [x1.first, current > x1.first ? l - current + x1.first : x1.first - current],
    [x1.last, current > x1.last ? current - x1.last : l - x1.last + current],
  ].max_by { |i, step| step }
  steps += step
  current = xi
  x1.delete(xi)
end

s1 = steps

steps = 0
current = 0

until x.empty?
  xi, step = [
    [x.last, current > x.last ? current - x.last : l - x.last + current],
    [x.first, current > x.first ? l - current + x.first : x.first - current],
  ].max_by { |i, step| step }
  steps += step
  current = xi
  x.delete(xi)
end

s2 = steps

puts [s1, s2].max