#include using namespace std; using std::cout; using std::cin; using std::endl; using ll=long long; using ld=long double; const ll ILL=2167167167167167167; const int INF=2100000000; #define rep(i,a,b) for (int i=(int)(a);i<(int)(b);i++) #define all(p) p.begin(),p.end() template using _pq = priority_queue, greater>; template ll LB(vector &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();} template ll UB(vector &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();} template bool chmin(T &a,T b){if(a>b){a=b;return 1;}else return 0;} template bool chmax(T &a,T b){if(a void So(vector &v) {sort(v.begin(),v.end());} template void Sore(vector &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});} bool yneos(bool a,bool upp=0){if(a){cout<<(upp?"YES\n":"Yes\n");}else{cout<<(upp?"NO\n":"No\n");}return a;} template void vec_out(vector &p,int ty=0){ if(ty==2){cout<<'{';for(int i=0;i<(int)p.size();i++){if(i){cout<<",";}cout<<'"'< T vec_min(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmin(ans,x);return ans;} template T vec_max(vector &a){assert(!a.empty());T ans=a[0];for(auto &x:a) chmax(ans,x);return ans;} template T vec_sum(vector &a){T ans=T(0);for(auto &x:a) ans+=x;return ans;} int pop_count(long long a){int res=0;while(a){res+=(a&1),a>>=1;}return res;} template bool inside(T l,T x,T r){return l<=x&&x> t; rep(i, 0, t) solve(); } void solve(){ int N, K; cin >> N >> K; vector A(K); rep(i, 0, K) cin >> A[i]; rep(i, 0, K) A.push_back(A[i] + 2 * N); vector p(N), nx(N); ll L = 0; rep(i, 0, K * 2){ while (L != N && L * 2 < A[i]) nx[L] = A[i + 1] / 2 + 1, p[L++] = A[i] / 2 + 1; } int l = 0, r = N / K + 1; auto mul = [&](vector a, vector b) -> vector { vector c(a.size()); rep(i, 0, a.size()) c[i] = a[b[i]]; return c; }; auto my_pow = [&](vector f, int t) -> vector { vector res(f.size()); rep(i, 0, f.size()) res[i] = i; while (t){ if (t & 1) res = mul(f, res); t /= 2; if (t) f = mul(f, f); } return res; }; while (r - l > 1){ int m = (r + l) / 2; vector q(N * 2 + 1); q[N * 2] = N * 2; rep(i, 0, N){ q[i] = max(i + m, p[i]); if (q[i] >= nx[i]) q[i] = N * 2; q[i + N] = min(N * 2, q[i] + N); } //cout << m << "\n"; //vec_out(q); q = my_pow(q, K); //vec_out(q); rep(i, 0, N) if (q[i] <= i + N) l = m; if (l != m) r = m; } //vec_out(nx); //vec_out(p); //vec_out(A); cout << l * 2 << "\n"; }