/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MM = 2002;
const int MAX = 200002;

int n, l;
long long a[MAX];
long long arr[MAX];
long long dyn[MM][MM][2];

long long recurse(int idx1, int idx2, int side) {
    if (idx1 >= idx2)
        return 0;
    if (dyn[idx1][idx2][side] != -1)
        return dyn[idx1][idx2][side];
    
    long long ans = 0;
    // Walk to the left
    if (side == 0) {
        long long dist = a[idx1 + 1] - a[idx1];
        ans = max(ans, recurse(idx1 + 1, idx2, 0) + dist);
    } else {
        long long dist = l - a[idx2] + a[idx1];
        ans = max(ans, recurse(idx1, idx2 - 1, 0) + dist);
    }
    // Walk to the right
    if (side == 0) {
        long long dist = a[idx1] + l - a[idx2];
        ans = max(ans, recurse(idx1 + 1, idx2, 1) + dist);
    } else {
        long long dist = a[idx2] - a[idx2 - 1];
        ans = max(ans, recurse(idx1, idx2 - 1, 1) + dist);
    }

    return dyn[idx1][idx2][side] = ans;
}

void dummy() {
    memcpy(a, arr, sizeof(a));
	memset(dyn, -1, sizeof(dyn));
	long long ans = 0;
	ans = max(ans, recurse(0, n - 1, 0) + a[0]);
	ans = max(ans, recurse(0, n - 1, 1) + l - a[n - 1]);
	fprintf(out, "%lld\n", ans);
}

long long prefL[MAX], prefR[MAX];

long long greedy2() {
    long long ans = 0;
    // All right
    ans = max(ans, a[n - 1]);
    // All left
    ans = max(ans, l - a[0]);
    
    prefL[0] = arr[0];
    for (int i = 1; i < n; i++)
        prefL[i] = prefL[i - 1] + arr[i];
    
    prefR[n - 1] = l - arr[n - 1];
    for (int i = n - 2; i >= 0; i--)
        prefR[i] = prefR[i + 1] + l - arr[i];

    // First step(s) right
    for (int i = 0; i < n - 1; i++) {
        long long cur = arr[i] * 2;
        int rem = n - i - 1;
        int halfL = rem / 2, halfR = rem / 2 + rem % 2;
        cur += (prefL[i + halfL] - prefL[i]) * 2;
        cur += prefR[n - halfR] * 2;
        if (halfR > halfL)
            cur -= l - arr[n - halfR];
        else
            cur -= arr[i + halfL];
        ans = max(ans, cur);
    }
    
    // First step(s) left
    for (int i = n - 1; i > 0; i--) {
        long long cur = (l - arr[i]) * 2;
        int rem = i;
        int halfL = rem / 2 + rem % 2, halfR = rem / 2;
        cur += prefL[halfL - 1] * 2;
        cur += (prefR[i - halfR] - prefR[i]) * 2;
        if (halfL > halfR)
            cur -= arr[halfL - 1];
        else
            cur -= l - arr[i - halfR];
        /*
        if (ans < cur) {
            fprintf(stderr, "New ans %lld\n", cur);
            fprintf(stderr, "i = %d, halfL = %d, halfR = %d\n", i, halfL, halfR);
            fprintf(stderr, "  >> adding in initial steps: %lld\n", (l - arr[i]) * 2);
            fprintf(stderr, "  >> adding from left: %lld\n", prefL[halfL - 1] * 2);
            fprintf(stderr, "  >> adding from right: %lld\n", (prefR[i - halfR] - prefR[i]) * 2);
            if (halfL > halfR)
                fprintf(stderr, "  >> subtracting from left: %lld\n", arr[halfL - 1]);
            else
                fprintf(stderr, "  >> subtracting from right: %lld\n", l - arr[i - halfR]);
        }
        */
        ans = max(ans, cur);
    }
    return ans;
}

long long greedy(int idx1, int idx2, int side) {
    long long ret = 0;
    while (idx2 - idx1 > MM - 2) {
        if (side == 0) {
            ret += a[idx1] + l - a[idx2];
            idx1++;
            side = 1;
        } else {
            ret += l - a[idx2] + a[idx1];
            idx2--;
            side = 0;
        }
        /*
        int distL = 0, distR = 0;
        if (side == 0) {
//            distL = arr[idx1] + l - arr[idx2];
//            distR = arr[idx1 + 1] - arr[idx1];
            distL = arr[idx1] + l - arr[idx2] + l - arr[idx2] + arr[idx1 + 1];
            distR = arr[idx1 + 1] - arr[idx1] + arr[idx1 + 1] + l - arr[idx2];
        } else {
//            distL = arr[idx2] - arr[idx2 - 1];
//            distR = l - arr[idx2] + arr[idx1];
            distL = arr[idx2] - arr[idx2 - 1] + l - arr[idx2 - 1] + arr[idx1];
            distR = l - arr[idx2] + arr[idx1] + arr[idx1] + l - arr[idx2 - 1];
        }
        if (distL > distR) {
            if (side == 0) {
                ret += arr[idx1] + l - arr[idx2];
                idx1++;
                side = 1;
            } else {
                ret += arr[idx2] - arr[idx2 - 1];
                idx2--;
            }
        } else {
            if (side == 0) {
                ret += arr[idx1 + 1] - arr[idx1];
                idx1++;
            } else {
                ret += l - arr[idx2] + arr[idx1];
                idx2--;
                side = 0;
            }
        }
        */
    }
    memset(dyn, -1, sizeof(dyn));
    for (int i = idx1; i <= idx2; i++)
        a[i - idx1] = arr[i];
    ret += recurse(0, idx2 - idx1, side);
    return ret;
}

void solve() {
//    long long ans = 0;
//    ans = max(ans, greedy(0, n - 1, 0) + arr[0]);
//    ans = max(ans, greedy(0, n - 1, 1) + l - arr[n - 1]);
    long long ans = greedy2();
	fprintf(out, "%lld\n", ans);
}

int main(void) {
	// in = fopen("B.in", "rt");
	
	fscanf(in, "%d %d", &l, &n);
	for (int i = 0; i < n; i++)
	    fscanf(in, "%lld", &arr[i]);
	sort(arr, arr + n);
	
	if (n < MM) {
	    dummy();
    } else {
    	solve();
    }
	
	return 0;
}

Measured memory_bytes: 67200