l, n = gets.split.map(&:to_i)
x = n.times.map { gets.to_i }
 
steps = 0
current = 0
 
until x.empty?
  xi, step = [
    [x.first, x.first - current],
    [x.last, l - x.last + current],
  ].max_by { |i, step| step }
  steps += step
  current = xi
  x.delete(xi)
end
 
puts steps