#include "bits/stdc++.h"
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<ll,ll> pii;

const ll MAX=2e6+9;
const ll INF=1e12;

ll N,L,start,last,final,res,X[MAX],prefix[MAX],suffix[MAX];

signed main()
{
	ios_base::sync_with_stdio(false);
  
	cin>>L>>N;	 
	for(int A=1;A<=N;A++)
		cin>>X[A];
	for(int it=0;it<2;it++)
	{
		for(int A=N;A>=1;A--)
			suffix[A]=suffix[A+1]+L-X[A];
		for(int A=1;A<=N;A++)
			prefix[A]=prefix[A-1]+X[A];
		for(int A=0;A<N;A++)
		{
			last=N-(A+1)/2+1;
			res=2*suffix[last];
			if(A%2==1)
				res-=L-X[last];
			start=last-(A/2+1);
			res+=2*prefix[last-1]-2*prefix[start-1];			
			if(A%2==0)
				res-=X[last-1];
			final=max(final,res);
		}
		for(int A=1;A<=N;A++)
			X[A]=L-X[A];
		sort(X+1,X+N+1);
	}
	cout<<final;
	return 0;
}