#include using namespace std; #define pb emplace_back #define mp make_pair using ll = long long; using pii = pair; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr int N = 5e5 + 10; int n, k, a[N]; bool ok(int st, int d){ if(st <= 0){ st = max(st + d, a[1] + 1); } int cur = st; for(int i=2; i<=k; ++i){ cur += d; if(cur < a[i]){ cur = a[i] + 1; } else if(cur > a[i + 1]){ return 0; } } if(cur + d <= a[k + 1] + 1){ return 1; } st = cur + d; cur = st - n * 2; if(cur > a[2]) return 0; for(int i=2; i<=k; ++i){ cur += d; if(cur < a[i]){ cur = a[i] + 1; } else if(cur > a[i + 1]){ return 0; } } return cur + d <= st; } bool ok(int d){ return ok(a[1] + 1, d) || ok(a[k] + 1 - n * 2, d); } void _main(){ cin >> n >> k; for(int i=1; i<=k; ++i) cin >> a[i]; if(k == 2){ cout << n << '\n'; return; } a[k + 1] = a[1] + n * 2; int low = 1, top = n, ans = 1, mid; while(low <= top){ mid = (low + top) >> 1; if(ok(mid * 2)){ ans = max(ans, mid); low = mid + 1; } else { top = mid - 1; } } cout << ans * 2 << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }