#include #include using namespace std; using namespace atcoder; istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); } istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } typedef long long ll; typedef vector> Graph; typedef pair pii; typedef pair pll; #define FOR(i,l,r) for (int i = l;i < (int)(r); i++) #define rep(i,n) for (int i = 0;i < (int)(n); i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define my_sort(x) sort(x.begin(), x.end()) #define my_max(x) *max_element(all(x)) #define my_min(x) *min_element(all(x)) template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const int INF = (1<<30) - 1; const ll LINF = (1LL<<62) - 1; const int MOD = 998244353; const int MOD2 = 1e9+7; const double PI = acos(-1); vector di = {1,0,-1,0}; vector dj = {0,1,0,-1}; #ifdef LOCAL # include # define debug(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__) #else # define debug(...) (static_cast(0)) #endif // https://noimi.hatenablog.com/entry/2021/05/02/195143?_ga=2.186800042.36757101.1619952706-2024379568.1619952706 // S : 持つデータの型 T : 範囲の型 template struct IntervalManager { struct node { T l, r; S x; node(const T &l, const T &r, const S &x) : l(l), r(r), x(x) {} constexpr bool operator<(const node &rhs) const { if(l != rhs.l) return l < rhs.l; return r < rhs.r; } }; const S unit; set s; IntervalManager(const S &u = S()) : unit(u) {} IntervalManager(const vector &a) { vector setter; for(int l = 0; l < a.size(); l++) { int r = l; for(; r < a.size() and a[l] == a[r]; r++) {} setter.emplace_back(l, r, a[l]); l = r - 1; } s = set(all(setter)); } // x を含んだセグメントのイテレータを返す typename set::iterator getIt(const T &x) { auto it = s.upper_bound(node(x, numeric_limits::max(), 0)); if(it == begin(s)) return end(s); it = prev(it); if(it->l <= x and x < it->r) return it; return end(s); } // x を含んだセグメントの情報を持ってくる node getSeg(const T &x) { auto it = getIt(x); if(it != end(s)) return *it; return node(x, x + 1, unit); } // x 以上をはじめて含むセグメントの iterator が帰ってくる typename set::iterator nextIt(const T &x) { auto it = s.upper_bound(node(x, numeric_limits::max(), 0)); if(it == begin(s)) return it; return prev(it); } // x に設定されてる値を取得 S get(const T &x) { auto it = getIt(x); if(it != end(s)) return it->x; return unit; } S operator[](T k) const { return get(k); } // [l, r) := x を set するときに消える区間加える区間ごとに関数を呼び出す // ただし、内包, 結合される [L, r) := x の区間も一旦消す template void update(T l, T r, const S &x, const ADD &add, const DEL &del) { auto it = s.lower_bound(node{l, 0, x}); while(it != end(s) and it->l <= r) { if(it->l == r) { if(it->x == x) { del(r, it->r, x); r = it->r, it = s.erase(it); } break; } if(it->r <= r) { del(it->l, it->r, it->x); it = s.erase(it); } else { if(it->x == x) { r = it->r; del(it->l, it->r, it->x); it = s.erase(it); } else { del(it->l, r, it->x); node n = *it; it = s.erase(it); it = s.emplace_hint(it, r, n.r, n.x); } } } if(it != begin(s)) { it = prev(it); if(it->r == l) { if(it->x == x) { del(it->l, it->r, it->x); l = it->l; it = s.erase(it); } } else if(l < it->r) { if(it->x == x) { del(it->l, it->r, it->x); l = min(l, it->l); r = max(r, it->r); it = s.erase(it); } else { if(r < it->r) { it = s.emplace_hint(next(it), r, it->r, it->x); it = prev(it); } del(l, min(r, it->r), it->x); node n = *it; it = s.erase(it); it = s.emplace_hint(it, n.l, l, n.x); } } } if(it != end(s)) it = next(it); debug(l, r); add(l, r, x); s.emplace_hint(it, l, r, x); } void update(T l, T r, const S &x) { update( l, r, x, [](T, T, S) {}, [](T, T, S) {}); } void show() { for(auto e : s) { cerr << "(" << "[" << e.l << ", " << e.r << "): " << e.x << ") "; } cerr << endl; } }; int main(){ cin.tie(0); ios_base::sync_with_stdio(false); ll D, Q; cin >> D >> Q; IntervalManager IM; ll ans = 0; auto ADD = [&](ll l, ll r, ll x){ chmax(ans, r - l); }; rep(i,Q){ ll A, B; cin >> A >> B; IM.update(A, B + 1, 1, ADD, ADD); cout << ans << endl; } }