#include using namespace std; using ll = long long; using P = pair; #define rep(i, a, b) for(ll i = a; i < b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) constexpr ll inf = 4e18; struct SetupIO { SetupIO() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(30); } } setup_io; int main(void) { int n, k; cin >> n >> k; n *= 2; vector a(2 * k); rep(i, 0, k) { cin >> a[i]; a[k + i] = a[i] + n; } int mi = 1e9, s = -1; rep(i, 0, 2 * k - 1) { if(a[i + 1] - a[i] < mi) { mi = a[i + 1] - a[i]; s = i; } } int ans = 0; rep(i, a[s] + 1, a[s + 1]) { int lower = 1, upper = n / k + 5; while(upper - lower > 1) { int mid = (lower + upper) / 2; int cur = i, idx = s; bool res = true; rep(j, 0, k - 1) { cur += mid; if(cur >= a[idx + 2]) { res = false; break; } cur = max(cur, a[idx + 1] + 1); idx++; } if(i + n - cur < mid) res = false; if(res) { lower = mid; } else { upper = mid; } } ans = max(ans, lower); } if(ans % 2 == 1) ans--; cout << ans << '\n'; }