#include using namespace std; #define rep(i,n) REP(i,0,n) #define REP(i,s,e) for(int i=(s); i<(int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--) #define all(r) r.begin(),r.end() #define rall(r) r.rbegin(),r.rend() typedef long long ll; typedef vector vi; typedef vector vl; const ll INF = 1e18; const ll MOD = 1e9 + 7; template T chmax(T& a, const T& b) { return a = (a > b ? a : b); } template T chmin(T& a, const T& b) { return a = (a < b ? a : b); } void yes_no(bool f, string yes = "Yes", string no = "No") { cout << (f ? yes : no) << "\n"; } #define DEBUG_MODE #ifdef DEBUG_MODE #define dump(x) cout << #x << " : " << x << " " #define dumpL(x) cout << #x << " : " << x << '\n' #define LINE cout << "line : " << __LINE__ << " " #define LINEL cout << "line : " << __LINE__ << '\n' #define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << " " #define dumpVL(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl #define STOP assert(false) #else #define dump(x) #define dumpL(x) #define LINE #define LINEL #define dumpV(v) #define dumpVL(v) #define STOP assert(false) #endif #define mp make_pair namespace std { template ostream& operator <<(ostream& out, const pair& a) { out << '(' << a.first << ", " << a.second << ')'; return out; } } // hankaikukan template struct RangeSet { using P = pair; set

st; const T INF; const P NG; RangeSet() :INF(numeric_limits::max() / 2), NG(P(INF, INF)) {} bool isIntersect(const T& x, const P& p) { return p.first <= x && x < p.second; } bool isIntersect(const P& p1, const P& p2) { if (p1.first < p2.first) return isIntersect(p2.first, p1); else return isIntersect(p1.first, p2); } bool isExist(const T& x) { auto it = st.lower_bound({ x, INF }); if (it == st.begin()) return false; --it; return isIntersect(x, *it); } P get(const T& x) { if (!isExist(x)) return NG; auto it = st.lower_bound({ x, INF }); --it; return *it; } P merge_range(const P& p1, const P& p2) { return P{ min(p1.first, p2.first), max(p1.second, p2.second) }; } void add(const P& p) { P add = p; { auto tmp = get(p.first - 1); if (tmp != NG) { add = merge_range(add, tmp); st.erase(tmp); } } { auto tmp = get(p.first); if (tmp != NG) { add = merge_range(add, tmp); st.erase(tmp); } } { auto tmp = get(p.second); if (tmp != NG) { add = merge_range(add, tmp); st.erase(tmp); } } erase(add); st.insert(add); } void add(const T& x) { add(P{ x, x + 1 }); } void erase(const P& p) { auto tmp = get(p.first); if (tmp == NG) return; auto it = st.find(tmp); while (it != st.end() && isIntersect(p, *it)) { auto erase_p = *it; if (erase_p.first < p.first) st.emplace(erase_p.first, p.first); if (p.second < erase_p.second) st.emplace(p.second, erase_p.second); st.erase(erase_p); it = st.upper_bound(erase_p); } } void erase(const T& x) { erase({ x, x + 1 }); } }; int main() { cin.tie(0); ios::sync_with_stdio(false); ll d, q; cin >> d >> q; RangeSet rs; ll ans = 0; rep(_, q) { ll a, b; cin >> a >> b; rs.add({ a, b + 1 }); auto p = rs.get(a); chmax(ans, p.second - p.first); cout << ans << '\n'; } return 0; }