DBG = !true
DBG2 = !true
require 'pp'
m,n = gets.split.map{|x| x.to_i}
a = []
for i in 0...n
  a << gets.to_i
end

if n==2
  v1st = [a[0], m-a[1]].max
  return [ a[1]-a[0], m+a[0]-a[1] ].max + v1st
end

d = Array.new(n)
d.map!{[]}
for j in 1...n
  v = [ a[j]-a[j-1], m+a[j-1]-a[j] ].max
  d[j-1][j] = [v,v]
end
for i in 2...n
  for j in i...n
    k = j-i
    vll = d[k+1][j][0] + a[k+1] - a[k]
    vlr = d[k+1][j][1] + m + a[k] - a[j]
    vrl = d[k][j-1][0] + m + a[k] - a[j]
    vrr = d[k][j-1][1] + a[j] - a[j-1]
    d[k][j] = [ [vll,vlr].max, [vrl,vrr].max ]
  end
end
pp d if DBG

mx = -1
for i in 1...n
  v = [  d[0][i][0] + a[0], d[0][i][1] + m - a[i] ].max
  mx = v if v > mx
end
for i in 0..(n-2)
  v = [  d[i][n-1][0] + a[i], d[i][n-1][1] + m - a[n-1] ].max
  mx = v if v > mx
end
print mx
