#define _USE_MATH_DEFINES #include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define MT make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< >(b,vector(c,d)) #define vvv(a,b,c,d,e) vector > >(b,vv(a,c,d,e)) using ll = long long; using pii = pair; using vi = vector; using vll = vector; using P = pair; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll D; int Q; while (cin >> D >> Q) { vll A(Q), B(Q); ll re = 0; set

S; rep(q, Q) { cin >> A[q] >> B[q]; ll lb = A[q], ub = B[q]; for (auto it = S.lower_bound(mp(A[q] - 1, 0)); it != S.end(); ) { ll l, r; tie(r, l) = *it; if (l > B[q] + 1)break; smin(lb, l); smax(ub, r); it = S.erase(it); } S.insert(mp(ub, lb)); smax(re, ub - lb + 1); cout << re << endl; } } }