#include <bits/stdc++.h>

// #define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll solve(vector<int>& pos, int L)
{
    int n = sz(pos);
    int cur = 0;
    int val = 0;
    int l = 0, r = n-1;
    while (l < r) {
        cur += 2*pos[l];
        cur += 2 * (L-pos[r]);
        l++; 
        r--; 
    }
    int a=0, b, c, cntb, cntc;
    if (n%2 == 0) {
        assert (l > r); 
        b = l;
        c = ++r;
        cur -= L-pos[r];
        cntb = 0, cntc = 1;
    }
    else {
        assert(l == r); 
        cur += pos[l]; 
        b = l; 
        cntb = 1, cntc = 2;
        c = ++r; 
    }
    
    pr(0) pr(a) pr(b) pr(c) pr(cntb) pr(cntc) nl 
    prl(cur) 
    
    ll best = cur;
    for (int skips=1; skips<=n-1; skips++) {
        pr(skips) pr(a) pr(b) pr(c) pr(cntb) pr(cntc) nl 
        cur -= 2*pos[a++];
        cur += pos[b];
        cntb++;
        if (cntb == 2) {
            b++;
            cntb = 0;
        }
        cur -= L-pos[c];
        cntc--; 
        if (cntc == 0) {
            c++;
            cntc = 2;
        }
        prl(cur)
        best = max(best,cur); 
    }
    prl(best) nl 
    return best; 
}

int32_t main()
{
    #ifdef DEBUG
    //freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int L,n;
    cin >> L >> n;
    vector<int> pos(n);
    for0(i,n)
        read(pos[i]);
    sort(all(pos));
    
    // int dp[n+5][n+5];
    // ms(dp,0);
    // for (int l=1; l<n; l++) {
        // for (int i=0; i<n; i++) {
            // int j = i+l; 
            // if (j >= n)
                // continue; 
            
            // int val1 = pos[i+1] - pos[i] + dp[i+1][j];
            // int val2 = pos[i] + L - pos[j] + dp[j][i+1];
            // dp[i][j] = max(val1, val2);
            
            // val1 = pos[j] - pos[j-1] + dp[j-1][i];
            // val2 = pos[i] + L - pos[j] + dp[i][j-1];
            // dp[j][i] = max(val1, val2);
        // }
    // }
    // print2D(dp,n,n);
    
    // int ans1 = pos[0] + dp[0][n-1]; 
    // int ans2 = L - pos[n-1] + dp[n-1][0];
    // int ans = max(ans1, ans2);
    // cout<<ans<<endl; 
    
    ll val1 = solve(pos, L);
    for0(i,n)
        pos[i] = L-pos[i];
    reverse(all(pos));
    ll val2 = solve(pos, L);
    cout<<max(val1,val2)<<endl; 
    return 0;
}


Measured memory_bytes: 1792