l, n = gets.chomp.split.map(&:to_i)
x = Array.new(n)
for i in 0..(n-1)
  x[i] = gets.chomp.to_i
end
ans = 0
now = 0
first = 0
last = n-1
loop do
  distf = distl = nextid = 0
  if now < x[last]
    distf = x[first] - now
    distl = l - x[last] + now
  else
    distf = l - now + x[first]
    distl = now - x[last]
  end
  if distf > distl
    ans += distf
    nextid = first
    first += 1
  elsif distf < distl
    ans += distl
    nextid = last
    last -= 1
  else
    idf = first + 1
    idl = last - 1
    loop do
      if first + 1 == last
        ans += distf
        nextid = first
        first += 1
        break
      elsif x[idf] - x[idf-1] != x[idl+1] - x[idl]
        if x[idf] - x[idf-1] > x[idl+1] - x[idl]
          ans += distf
          nextid = first
          first += 1
        else
          ans += distl
          nextid = last
          last -= 1
        end
        break
      end
      idf += 1
      idl -= 1
    end
  end
  if first > last
    break
  end
  now = x[nextid]
end
puts ans