#include using namespace std; using ll = long long; using i128 = __int128_t; using pll = pair; const int INF = 1000100100; const ll INFF = 1000100100100100100LL; #define overload4(_1, _2, _3, _4, name, ...) name #define rep1(i, n) for (ll i = 0; i < ll(n); i++) #define rep2(i, l, r) for (ll i = ll(l); i < ll(r); i++) #define rep3(i, l, r, d) for (ll i = ll(l); (d) > 0 ? i < ll(r) : i > ll(r); i += d) #define rep(...) overload4(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__) #define per(i, n) for (int i = (n) - 1; i >= 0; --i) #define yesno(f) cout << (f ? "Yes" : "No") << endl; #define YESNO(f) cout << (f ? "YES" : "NO") << endl; #define all(a) (a).begin(), (a).end() template void printvec(const vector &v) { int n = v.size(); rep(i, n) cout << v[i] << (i == n - 1 ? "" : " "); cout << '\n'; } template void printvect(const vector &v) { for (auto &vi : v) cout << vi << '\n'; } template void printvec2(const vector> &v) { for (auto &vi : v) printvec(vi); } template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second; } template bool chmax(T &x, const T &y) { return (x < y) ? (x = y, true) : false; } template bool chmin(T &x, const T &y) { return (x > y) ? (x = y, true) : false; } #ifdef LOCAL // https://zenn.dev/sassan/articles/19db660e4da0a4 #include "cpp-dump-main/dump.hpp" #define dump(...) cpp_dump(__VA_ARGS__) CPP_DUMP_DEFINE_DANGEROUS_EXPORT_OBJECT(val()); #else #define dump(...) #endif struct io_setup { io_setup() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << fixed << setprecision(15); } } io_setup; template struct RangeSet { set> st; T TINF; RangeSet() { TINF = numeric_limits::max() / 2; st.emplace(TINF, TINF); st.emplace(-TINF, -TINF); } bool covered(T l, T r) { asssert(l <= r); auto it = prev(st.lower_bound({l + 1, l + 1})); return (it->first <= l && r <= it->second); } bool covered(T x) { return covered(x, x); } pair covered_by(T l, T r) { assert(l <= r); auto it = prev(st.lower_bound({l + 1, l + 1})); if (it->first <= l && r <= it->second) return *it; else return make_pair(-TINF, -TINF); } pair covered_by(T x) { return covered_by(x, x); } // insert [l,r] 区間の増加量を返す T insert(T l, T r) { assert(l <= r); auto it = prev(st.lower_bound({l + 1, l + 1})); if (it->first <= l && r <= it->second) return T(0); T sum_erased = T(0); if (it->first <= l && l <= it->second + 1) { l = it->first; sum_erased += it->second - it->first + 1; it = st.erase(it); } else it = next(it); while (r > it->second) { sum_erased += it->second - it->first + 1; it = st.erase(it); } if (it->first - 1 <= r and r <= it->second) { sum_erased += it->second - it->first + 1; r = it->second; st.erase(it); } st.emplace(l, r); return r - l + 1 - sum_erased; } T insert(T x) { return insert(x, x); } // erase [l,r] 区間の減少量を返す T erase(T l, T r) { assert(l <= r); auto it = prev(st.lower_bound({l + 1, l + 1})); if (it->first <= l && r <= it->second) { // 完全に1つの区間に包含されている if (it->first < l) st.emplace(it->first, l - 1); if (r < it->second) st.emplace(r + 1, it->second); st.erase(it); return r - l + 1; } T ret = T(0); if (it->first <= l && l <= it->second) { ret += it->second - l + 1; // 消えた if (it->first < l) st.emplace(it->first, l - 1); it = st.erase(it); // 次へ } else it = next(it); while (it->second <= r) { ret += it->second - it->first + 1; it = st.erase(it); } // 右端が区間の間にあるか if (it->first <= r && r <= it->second) { ret += r - it->first + 1; if (r < it->second) st.emplace(r + 1, it->second); st.erase(it); } return ret; } T erase(T x) { return erase(x, x); } // pとqが同じ区間にいるか covered と同じ bool same(T p, T q) { return covered(p, q); } int size() { return (int)st.size() - 2; } // x以上で最も小さい,区間に含まれない数を返す T mex(T x = 0) { auto it = prev(st.lower_bound({x + 1, x + 1})); if (it->first <= x && x <= it->second) return it->second + 1; else return x; } void debug() { cout << "RangeSet : "; for (auto &p : st) { if (p.first == -TINF or p.second == TINF) continue; cout << "[" << p.first << ", " << p.second << "] "; } cout << "\n"; } }; void solve() { ll d, q; cin >> d >> q; ll ans = 0; RangeSet S; while (q--) { ll a, b; cin >> a >> b; S.insert(a, b); pll p = S.covered_by(a, b); chmax(ans, p.second - p.first + 1); cout << ans << endl; } } int main() { int t; // cin >> t; t = 1; while (t--) { solve(); } }