#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a) - 1; i >= (b); i--)
#define fore(e, v) for(auto &&e : v)
#define all(a) begin(a), end(a)
#define si(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template <typename T, typename S> bool chmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; }
template <typename T, typename S> bool chmax(T &a, const S &b) { return a < b ? a = b, 1 : 0; }

const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;

#define i128 __int128_t

struct _ {
    _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;

int rnd(int l, int r) {
    static mt19937_64 mt(time(NULL));
    return uniform_int_distribution<int>(l, r - 1)(mt);
}
int main() {
    int n, k;
    cin >> n >> k;
    n *= 2;
    vl a(k);
    fore(e, a) cin >> e, --e;
    vi nxt(n);
    a.eb(a[0] + n);
    rep(i, n) {
        int j = a[lb(a, i)];
        nxt[i] = j - i;
    }
    int ok = 0, ng = n / 2;
    // rep(i, n) { cout << nxt[i] << " "; }
    // cout << endl;
    while(ok + 1 < ng) {
        int mid = ok + ng >> 1;
        int d = mid * 2;
        bool flag = false;
        // cerr << d << endl;
        rep((n + k - 1) / k * 50) {
            ll now = rnd(0, n / 2) * 2 + 1;
            ll st = now;
            int rem = now % n;
            rep(k) {
                int add = max(nxt[rem] + 1, d);
                rem += add;
                if(rem >= n) rem -= n;
                now += add;
            }
            // cout << now << endl;
            if(now <= st + n) {
                flag = true;
                break;
            }
        }
        // cout << d << " " << flag << endl;
        (flag ? ok : ng) = mid;
    }
    cout << ok * 2 << endl;
}