import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    long L;
    int n;
    scan(L, n);
    auto x = iota(n).map!(i => readln.chomp.to!int).array;

    if (n > 5000) {
        return;
    }

    auto dp = new long[][][](n, n, 2);
    // dp(l, r, 0 or 1) 0 -> 左側, 1 -> 右側
    fillAll(dp, -1);

    long dfs(int l, int r, int b) {
        if (dp[l][r][b] != -1) {
            return dp[l][r][b];
        }
        if (r == l + 1) {
            dp[l][r][b] = max(x[r] - x[l], x[l] - x[r] + L);
            return dp[l][r][b];
        }

        // l のほうにいる
        if (b == 0) {
            dp[l][r][b] = max(x[l+1] - x[l] + dfs(l+1, r, 0),
                            x[l] - x[r] + L + dfs(l+1, r, 1));
        }
        else {
            dp[l][r][b] = max(x[r] - x[r-1] + dfs(l, r-1, 1),
                            x[l] - x[r] + L + dfs(l, r-1, 0));
        }

        return dp[l][r][b];
    }



    long ans = max(x[0] + dfs(0, n-1, 0), L - x[n-1] + dfs(0, n-1, 1));

    debug {
        foreach (l ; 0 .. n) {
            foreach (r ; 0 .. n) {
                foreach (b ; 0 .. 2) {
                    stderr.writefln("l=%d, r=%d, b=%d: %d", l, r, b, dp[l][r][b]);
                }
            }
        }
        //stderr.writeln(dp);
    }

    writeln(ans);
}











void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}