l, n = gets.chomp.split(" ").map(&:to_i)
tree_array = []
for i in 0..n-1
  tree_array[i] = gets.chomp.to_i
end

position = 0
result = 0
tree_array.sort!
tree_array_start_home = tree_array.map{ |tree| l - tree < tree ? tree = -1 * (l - tree) : tree }
tree_array_start_home.sort!
if tree_array_start_home.last.abs + tree_array_start_home.first.abs > l / 2
    right_walk_length = tree_array.inject(:+)
    left_tree_array = tree_array.map{|tree| l - tree }
    left_walk_length = left_tree_array.inject(:+)
    if left_walk_length > right_walk_length
      print("#{right_walk_length}\n")
    else
      print("#{left_walk_length}\n")
    end
else
  if tree_array_start_home.last.abs > tree_array_start_home.first.abs
    print("#{tree_array_start_home.last.abs + (tree_array_start_home.first.abs * 2)}\n")
  else
    print("#{tree_array_start_home.first.abs + (tree_array_start_home.last.abs * 2)}\n")
  end
end