#include using namespace std; using ll = long long; constexpr int MOD = 998244353; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, l, r) for (int i = (l); i < (int)(r); i++) namespace Lib { struct range_set { using all2 = array; static constexpr ll minf = numeric_limits::min(); static constexpr ll pinf = numeric_limits::max(); set intervals; int add(all2 a) { auto [l, r] = a; int ret = 1; // 既存の区間に完全に包含される場合 { auto it = intervals.upper_bound(all2({l, pinf})); if (it != intervals.begin()) { it--; if ((*it)[1] >= r) return 0; if ((*it)[1] >= l) l = (*it)[0]; } } auto it = intervals.lower_bound(all2({l, minf})); while (1) { if (it != intervals.end() && (*it)[0] <= r) { r = max(r, (*it)[1]); auto it2 = it; it++; intervals.erase(it2); ret -= 1; } else { break; } } intervals.insert({l, r}); return ret; } int erase(all2 a) { auto [l, r] = a; int ret = 0; { auto it = intervals.lower_bound(all2({l, minf})); if (it != intervals.begin()) { it--; if ((*it)[1] > l) { auto [l2, r2] = *it; intervals.erase(it); intervals.insert({l2, l}); if (r2 > r) { intervals.insert({r, r2}); ret += 1; } } } } auto it = intervals.lower_bound(all2({l, minf})); while (1) { if (it != intervals.end() && (*it)[1] <= r) { auto it2 = it; it++; intervals.erase(it2); ret -= 1; } else { break; } } if (it != intervals.end() && (*it)[0] < r) { auto [l2, r2] = *it; intervals.erase(it); intervals.insert({r, r2}); } return ret; } pair cover(all2 b) { auto [l, r] = b; auto it = intervals.upper_bound(all2({l, pinf})); if (it != intervals.begin()) { it--; if ((*it)[0] <= l && r <= (*it)[1]) { all2 ret = *it; return make_pair(true, ret); } } return make_pair(false, all2({0, 0})); } }; } // namespace Lib int main() { ios::sync_with_stdio(false); cin.tie(nullptr); Lib::range_set S; ll D, Q; cin >> D >> Q; ll ans = 0; while (Q--) { ll A, B; cin >> A >> B; S.add({A, B + 1}); auto [ok, lr] = S.cover({A, A + 1}); assert(ok); ans = max(ans, lr[1] - lr[0]); cout << ans << '\n'; } }