#include using namespace std; template struct Range { T l, r; Range(T l, T r) : l(l), r(r) { if (l > r) l = r = 0ll; } Range() : Range(0ll, 0ll) {} Range operator&(Range b) const { T nl = max(l, b.l), nr = min(r, b.r); if (nl < nr) return Range(nl, nr); else return Range(); } Range operator|(Range b) const { if (max(l, b.l) > min(r, b.r)) return Range(); return Range(min(l, b.l), max(r, b.r)); } bool empty() const { return l == r; } bool contains(T x) const { return l <= x && x < r; } T count() const { return r - l; } bool operator<(const Range& b) const { return (l != b.l) ? l < b.l : r < b.r; } }; template struct RangeSet { set> ranges; RangeSet() {} int64_t cnt = 0; void insert(Range r) { if (r.empty()) return; auto it = ranges.lower_bound(r); if (it != ranges.end() && it->l == r.l && r.r <= it->r) return; if (it != ranges.begin()) { auto pit = prev(it); if (r.r <= pit->r) return; if (r.l <= pit->r) { r.l = pit->l; cnt -= pit->count(); ranges.erase(pit); } } while (it != ranges.end() && r.r >= it->l) { r.r = max(r.r, it->r); cnt -= it->count(); it = ranges.erase(it); } cnt += r.count(); ranges.insert(r); } void erase(Range r) { if (r.empty()) return; auto it = ranges.lower_bound(r); if (it != ranges.end() && it->l == r.l && r.r <= it->r) { Range nl = Range(it->l, r.l); Range nr = Range(r.r, it->r); cnt -= it->count(); cnt += nl.count() + nr.count(); ranges.erase(it); if (!nl.empty()) ranges.insert(nl); if (!nr.empty()) ranges.insert(nr); return; } if (it != ranges.begin()) { auto pit = prev(it); if (r.r <= pit->r) { Range nl = Range(pit->l, r.l); Range nr = Range(r.r, pit->r); cnt -= pit->count(); cnt += nl.count() + nr.count(); ranges.erase(pit); if (!nl.empty()) ranges.insert(nl); if (!nr.empty()) ranges.insert(nr); return; } if (r.l <= pit->r) { Range nl = Range(pit->l, r.l); cnt -= pit->count(); ranges.erase(pit); if (!nl.empty()) ranges.insert(nl); } } while (it != ranges.end() && r.r >= it->l) { if (it->r <= r.r) { cnt -= it->count(); it = ranges.erase(it); } else { Range nr = Range(r.r, it->r); cnt -= it->count(); it = ranges.erase(it); if (!nr.empty()) ranges.insert(nr); } } } Range get(T x) { auto it = ranges.lower_bound(Range(x, numeric_limits::max())); if (it != ranges.begin()) { auto pit = prev(it); if (pit->contains(x)) return *pit; } return Range(); } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); using ll = long long; ll d, q; cin >> d >> q; RangeSet rs; ll ans = 0; while (q--) { ll a, b; cin >> a >> b; rs.insert({a, b + 1}); auto r = rs.get(a); ans = max(ans, r.count()); cout << ans << '\n'; } }