l, n = gets.split.map(&:to_i)
pos = n.times.map{ gets.to_i }
r_pos = pos.map{ |x| l - x }.reverse
q = [[pos, r_pos, 0, 0, 0]]
list = [0] * n

until q.empty?
  pos, r_pos, s, total, i = q.shift
  q << [pos[1..-1].map{ |x| x - pos[0] }, r_pos[0...-1].map{ |x| x + pos[0] }, pos[0], total + pos[0], i + 1] unless pos.size <= 1
  q << [pos[0...-1].map{ |x| x + r_pos[0] }, r_pos[1..-1].map{ |x| x - r_pos[0] }, pos[-1], total + r_pos[0], i + 1] unless pos.size <= 1
  list[i] = total + pos[0] if list[i] < total + pos[0]
  list[i] = total + r_pos[0] if list[i] < total + r_pos[0]
end

puts list[n - 1]
    