#ifndef call_include #define call_include #include using namespace std; #endif template struct SegmentSet { private: map mp; public: SegmentSet() : mp(){}; void insert(T x) { insert(x, x); } void insert(T l, T r) { assert(l <= r); auto itr_l = mp.upper_bound(l), itr_r = mp.upper_bound(r + 1); if(itr_l != mp.begin()) { if((--itr_l)->second < l - 1) itr_l++; } if(itr_l != itr_r) { l = std::min(l, itr_l->first); r = std::max(r, prev(itr_r)->second); mp.erase(itr_l, itr_r); } mp[l] = r; } void erase(T x) { erase(x, x); } void erase(T l, T r) { assert(l <= r); auto itr_l = mp.upper_bound(l), itr_r = mp.upper_bound(r); if(itr_l != mp.begin()) { if((--itr_l)->second < l) itr_l++; } if(itr_l == itr_r) return; T tmp_l = itr_l->first, tmp_r = prev(itr_r)->second; mp.erase(itr_l, itr_r); if(tmp_l < l) mp[tmp_l] = l - 1; if(r < tmp_r) mp[r + 1] = tmp_r; } pair get_seg(T x) { auto itr = mp.upper_bound(x); if(itr == mp.begin() or (--itr)->second < x) return pair(0, -1); return pair(itr->first, itr->second); } T min() { return mp.begin()->first; } T max() { return mp.rbegin()->second; } T mex(T x = 0) { pair p = get_seg(x); if(p.first > p.second) return x; return p.second + 1; } bool same(T x, T y) { pair p = get_seg(x); return p.first <= p.second and p.first <= y and y <= p.second; } int size() { return int(mp.size()); } void out() { for(auto [l, r] : mp) cout << "[" << l << ", " << r << "]\n"; } }; int main() { long long D; int Q; SegmentSet s; cin >> D >> Q; long long ans = 0; for(int i = 0; i < Q; i++) { long long A, B; cin >> A >> B; s.insert(A, B); auto p = s.get_seg(A); ans = max(ans, p.second - p.first + 1); cout << ans << endl; } }