#include <bits/stdc++.h>
using namespace std;

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
void output_vectors(vector<vector<T>>& vs, ostream* os) {
    for (auto& v : vs) {
        rep(i, 0, v.size()) {
            *os << v[i];
            if (i == i64(v.size()) - 1)
                *os << endl;
            else
                *os << " ";
        }
    }
}

template <typename T>
vector<vector<T>> generate_random(i64 len, T minimum, T maximum, i64 num, bool unique = false, ostream* os = nullptr) {
    static mt19937 mt(time(nullptr));
    {
        T all = 1;
        rep(i, 0, len){
            all *= maximum - minimum + 1;
            if(all>=num) break;
        }
        assert(all >= num);
    }
    if (unique) assert(len <= maximum - minimum + 1);

    if (len == 0) return {{}};

    uniform_int_distribution<> dist(minimum, maximum);
    vector<vector<T>> res;
    while (res.size() < num) {
        auto sub = generate_random(len - 1, minimum, maximum, 1, unique)[0];
        T x = dist(mt);
        while (unique and find(begin(sub), end(sub), x) != end(sub)) x = dist(mt);
        sub.emplace_back(x);
        res.emplace_back(sub);
    }

    if (os != nullptr) output_vectors(res, os);

    return res;
}

template <typename T>
vector<vector<T>> generate_random_monotone(i64 len, T minimum, T maximum, i64 num, bool inc_or_dec, bool strict, ostream* os = nullptr) {
    assert(minimum <= maximum);
    if (strict) assert(len <= maximum - minimum + 1);

    auto res = generate_random(len, minimum, maximum, num, strict);
    for(auto& v:res){
        if(inc_or_dec) sort(begin(v),end(v));
        else sort(rbegin(v),rend(v));
    }

    if (os != nullptr) output_vectors(res, os);

    return res;
}

void experiment(){
    i64 L,N;
    cin >> L >> N;

    vector<i64> X=generate_random_monotone<i64>(N,1,L-1,1,true,true)[0];
    X.insert(begin(X),0);

    function<pair<i64,vector<int>>(set<i64>,i64)> bruteforce=[&](const set<i64> visited, const i64 i){
        if(visited.size()==N+1) return make_pair(i64(0),vector<int>{});

        pair<i64,vector<int>> res;
        {
            i64 j=i;
            while(visited.find(j)!=visited.end()){
                --j;
                j=(j+N+1)%(N+1);
            }
            i64 d=j<i?X[i]-X[j]:L-(X[j]-X[i]);
            auto tmp=visited;
            tmp.insert(j);

            auto sub=bruteforce(tmp,j);
            res=sub;
            res.first+=d;
            res.second.push_back(-1);
        }
        {
            i64 j=i;
            while(visited.find(j)!=visited.end()){
                ++j;
                j=(j+N+1)%(N+1);
            }
            i64 d=j>i?X[j]-X[i]:L-(X[i]-X[j]);
            auto tmp=visited;
            tmp.insert(j);

            auto sub=bruteforce(tmp,j);
            if(sub.first+d>res.first){
                res=sub;
                res.first+=d;
                res.second.push_back(1);
            }
        }
        return res;
    };

    auto res=bruteforce({0},0);
    reverse(begin(res.second),end(res.second));
    cerr << X << endl;
    cerr << res.second << endl;
}

i64 solve2(i64 L, i64 N, vector<i64> X){
    i64 res=X[N],d=X[N],p=0;
    i64 plus=N; // L-(X[plus]-X[plus-1])が足される
    i64 i=N,j=N-1,c=1,s=X[N]-X[N-1]; // マイナスする必要のある多項式を管理するiが末尾の添え字jが先頭の添え字, cが末尾の添え字の係数
    for(i64 k=N-1; k>=1; --k){
        d+=L-(X[plus]-X[plus-1]);
        d-=s;
        res=max(res,d);
        if(k>=2){
            ++p;
            if(p%2==0){
                --plus;
            }

            s-=X[i]-X[i-1];
            s+=2*(X[j]-X[j-1]);
            --c;
            if(c==0){
                c=2;
                --i;
            }
            --j;
        }
    }
    return res;
}

void solve(){
    i64 L,N;
    cin >> L >> N;

    vector<i64> X(N+1);
    rep(i,1,N+1) cin >> X[i];

    i64 ans=solve2(L,N,X);
    rep(i,0,N+1) X[i]=(L-X[i])%L;
    sort(begin(X),end(X));
    ans=max(ans,solve2(L,N,X));

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    //experiment();
    solve();
    return 0;
}


Measured memory_bytes: 3428