#include <bits/stdc++.h>
using namespace std;
struct P
{
    int x,y;
    bool operator<(const P &a)const{
        if(y!=a.y) return y>a.y;
        return x>a.x;

    }

};
vector<int> v;
//bitset<4001000> b;
int i,n,d,m,k,a,b,c;
long long e[2222][2222][3];
long long o[221111];
long long l[201111];
long long j[201111];
int dx[10]={0,1,0,-1,1,1,-1,-1},dy[10]={1,0,-1,0,1,-1,1,-1},dz[10]={0,0,0,0,1,-1};
long long mod=1000000007,mod2=1000000009,mod3=2017;
long long x,z,y;
double pi=3.14159265;
P u[1];
stack<int> s;
//set<long long> s;
//priority_queue<int> q;
queue<int> q;
//string r;
char r[1];
//2147483647
//'1'==49;
//'A'==65;
//'a'==97;
//unordered_
//map<int,int> p;


/*struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
unordered_map<long long, int, custom_hash> p;//safe_map;
*/
bool as(P a,P b)
{
    return a.x+a.y<b.x+b.y;
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//rng();

long long f(int n,int m,int i)
{
    long long x=0;
    if((m-n+1)%2==0&&i==0)
    {
        x=(l[(m+n)/2]-l[n-1])-o[(m+n)/2]+(j[(m+n)/2+2]-j[m+1])+max(o[(m+n)/2+1]-o[(m+n)/2],o[(m+n)/2]+(a-o[(m+n)/2+1]));
        //
        //printf("%d %d %lld %lld\n",n,m,l[(m+n)/2]-o[(m+n)/2],(j[(m+n)/2+2]-j[m+1]));
        //x=l[(m-n-1)/2]-l[n-1]+j[(m-n-1)/2+1]-((long long)a*2*(b-m)-j[m+1])+max(o[(m-n+1)/2+1]-o[(m-n+1)/2],);
    }
    else if((m-n+1)%2==0&&i==1)
    {

        x=l[(m+n)/2-1]-l[n-1]-(a-o[(m+n)/2+1])+j[(m+n)/2+1]-j[m+1]+max(o[(m+n)/2+1]-o[(m+n)/2],o[(m+n)/2]+(a-o[(m+n)/2+1]));
        //printf("%d %d %lld %lld\n",n,m,l[(m+n)/2-1]-l[n-1],(j[(m+n)/2+1]-j[m+1]));//-a+o[(m-n+1)/2+1]);
    }
    else if(i==0)
    {
        if(n==m) x=max(o[n],o[n+1]-o[n]-(a-o[n+1]));
        //printf("&&&%lld\n",x);
        else x=(l[(m+n)/2-1]-l[n-1])-(a-o[(m+n)/2+1])+(j[(m+n)/2+1]-j[m+1])+max(o[(m+n)/2+1]-o[(m+n)/2],o[(m+n)/2]+(a-o[(m+n)/2+1]));
        //printf("%d %d %lld %lld\n",n,m,l[(m+n)/2-1],-a+o[(m+n)/2+1]+(j[(m+n)/2+1]-j[m+1]));
        //
    }
    else
    {
        if(n==m) x=max(o[n]-o[n-1]*2,a-o[n]);
        //printf("@@@%lld\n",x);
        else x=(l[(m+n)/2-1]-l[n-1])-o[(m+n)/2-1]+(j[(m+n)/2+1]-j[m+1])+max(o[(m+n)/2]-o[(m+n)/2-1],o[(m+n)/2-1]+(a-o[(m+n)/2]));
    }
    return x;
}

long long g(int n,int m,int i)
{
    if(n>m) return 0;
    if(e[n][m][i]>=0) return e[n][m][i];
    if(i)
        return e[n][m][i]=max(g(n,m-1,i)+o[m+1]-o[m],g(n+1,m,0)+o[n]+(a-o[m+1]));
    return e[n][m][i]=max(g(n,m-1,1)+o[n-1]+a-o[m],g(n+1,m,i)+o[n]-o[n-1]);
}

int main()
{
    scanf("%d %d",&a,&b);
    o[b+1]=a;
    for(int t=1;t<=b;t++)
        scanf("%d",&o[t]);
    if(b<=2000)
    {
        memset(e,-1,sizeof(e));
        printf("%lld",max(g(1,b,1),g(1,b,0)));
        return 0;
    }
    if(b==1)
    {
        printf("%d",max(o[1],a-o[1]));
    }
    for(int t=1;t<=b;t++)
        l[t]=l[t-1]+o[t]*2;
    for(int t=b;t>0;t--)
        j[t]=j[t+1]+(o[b+1]-o[t])*2;
    for(int t=1;t<b;t++)
    {
        x=max(max(f(t+1,b,1)+o[t]*2,f(1,b-t,0)+(a-o[b-t+1])*2),x);
        //printf("%lld\n",x);
    }
    //for(int t=1;t<=b;t++)
        printf("%lld ",x);
}


Measured memory_bytes: 118912