#include using namespace std; #define DEBUG(x) cerr<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair template pair operator+(const pair &s, const pair &t) { return pair(s.first + t.first, s.second + t.second); } template pair operator-(const pair &s, const pair &t) { return pair(s.first - t.first, s.second - t.second); } template ostream& operator<<(ostream& os, pair p) { os << "(" << p.first << ", " << p.second << ")"; return os; } #define X first #define Y second #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define rrep1(i,n) for(int i=(int)(n);i>0;i--) #define REP(i,a,b) for(int i=a;i bool chmax(T &a, const T &b) { if (a bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; } #define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end()); const ll inf = 1000000001; const ll INF = (ll)1e18 + 1; const long double pi = 3.1415926535897932384626433832795028841971L; #define Sp(p) cout<> { private: bool flagToMergeAdjacentSegment; public: RangeSet() {} RangeSet(bool flagToMergeAdjacentSegment) : flagToMergeAdjacentSegment(flagToMergeAdjacentSegment) {} // get the iterator that x is in // noexist -> map.end() auto get(ll x) const { auto itr = upper_bound(pll(x, 1e18)); if (itr == begin() or (--itr)->second < x) return end(); return itr; } // insert segment [l, r] // return merged range auto add(pll lr) { while (true) { auto itr = lower_bound(pll(lr.first, -INF)); if (itr == end()) break; ll r = -INF; if (itr->first <= lr.second + (int)flagToMergeAdjacentSegment) r = max(lr.second, itr->second); if (r == -INF) break; lr.second = r; erase(itr); } while (true) { auto itr = lower_bound(pll(lr.first, -INF)); if (itr == begin()) break; itr--; ll l = INF; ll r = -INF; if (itr->second + (int)flagToMergeAdjacentSegment >= lr.first) { l = min(lr.first, itr->first); r = max(lr.second, itr->second); } if (l == INF) break; lr.first = l; lr.second = r; erase(itr); } insert(lr); return lower_bound(lr); } // Are x1 and x2 in the same range? bool same(ll x1, ll x2) { auto itr = get(x1); return itr != end() and (itr->first <= x2 and x2 <= itr->second); } }; signed main() { int d, q; cin >> d >> q; ll ans = 0; RangeSet st(true); while (q--) { int a, b; cin >> a >> b; auto itr = st.add(pll(a, b)); chmax(ans, itr->second - itr->first + 1); cout << ans << endl; // // for (auto itr = st.begin(); itr != st.end(); itr++) { // // cout << *itr << " "; // // } // cout << endl; } }