#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<vector>
#include<stack>
#include<map>
#include<set>
#define Run(i,l,r) for(int i=l;i<=r;i++)
#define Don(i,l,r) for(int i=l;i>=r;i--)
#define ll long long
#define ld long double
#define inf 0x3f3f3f3f
#define mk make_pair
#define fir first
#define sec second
using namespace std;
const int N=200010;
int n,m,a[N];
ll sum1[N],sum2[N];
int main(){
//	freopen("B.in","r",stdin);
//	freopen("B.out","w",stdout);
	scanf("%d%d",&m,&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum1[i]=sum1[i-1]+a[i];
		sum2[i]=sum2[i-1]+m-a[i];
	}
	ll ans=0; 
	for(int i=1;i<n;i++){
		int mn = min(i,n-i);
		ll t1 = sum1[i] - sum1[i - mn], t2 = sum2[i + mn] - sum2[i];
		ll p1 = a[i] , p2 = m - a[i+1];
		ans = max(ans , (t1 + t2) * 2 - min(p1,p2) );
	}
	for(int i=1;i<=n;i++){
		int mn = min(i-1,n-i);
		ll t1 = sum1[i-1] - sum1[i-1-mn] , t2 = sum2[i+mn] - sum2[i]; 
		ll p1 = a[i] , p2 = m - a[i];
		ans = max(ans , (t1 + t2) * 2 + max(p1,p2));
	}
	cout<<ans<<endl;
	return 0;
}//by tkys_Austin;

