#define _USE_MATH_DEFINES #include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; template struct SetManagedByInterval { std::set> interval{ {std::numeric_limits::lowest(), std::numeric_limits::lowest()}, {std::numeric_limits::max(), std::numeric_limits::max()}, }; bool contains(T x) const { return contains(x, x); } bool contains(T left, T right) const { auto it = interval.lower_bound({left, left}); if (left < it->first) it = std::prev(it); return it->first <= left && right <= it->second; } bool erase(T x) { auto it = interval.lower_bound({x, x}); if (it->first == x) { T right = it->second; interval.erase(it); if (x + 1 <= right) interval.emplace(x + 1, right); return true; } it = std::prev(it); T left, right; std::tie(left, right) = *it; if (right < x) return false; interval.erase(it); interval.emplace(left, x - 1); if (x + 1 <= right) interval.emplace(x + 1, right); return true; } T erase(T left, T right) { assert(left <= right); auto it = interval.lower_bound({left, left}); T res = 0; for (; it->second <= right; it = interval.erase(it)) res += it->second - it->first + 1; if (it->first <= right) { res += right - it->first + 1; T r = it->second; interval.erase(it); it = interval.emplace(right + 1, r).first; } if (left <= std::prev(it)->second) { it = std::prev(it); res += it->second - left + 1; T l = it->first; interval.erase(it); interval.emplace(l, left - 1); } return res; } bool insert(T x) { auto it = interval.lower_bound({x, x}); if (it->first == x || x <= std::prev(it)->second) return false; T left = x, right = x; if (x + 1 == it->first) { right = it->second; it = interval.erase(it); } if (std::prev(it)->second == x - 1) { it = std::prev(it); left = it->first; interval.erase(it); } interval.emplace(left, right); return true; } T insert(T left, T right) { assert(left <= right); auto it = interval.lower_bound({left, left}); if (left <= std::prev(it)->second) { it = std::prev(it); left = it->first; } if (left == it->first && right <= it->second) return 0; T res = 0; for (; it->second <= right; it = interval.erase(it)) res -= it->second - it->first + 1; if (it->first <= right) { res -= it->second - it->first + 1; right = it->second; it = interval.erase(it); } res += right - left + 1; if (right + 1 == it->first) { right = it->second; it = interval.erase(it); } if (std::prev(it)->second == left - 1) { it = std::prev(it); left = it->first; interval.erase(it); } interval.emplace(left, right); return res; } T mex(T x = 0) const { auto it = interval.lower_bound({x, x}); if (x <= std::prev(it)->second) it = std::prev(it); return x < it->first ? x : it->second + 1; } friend std::ostream &operator<<(std::ostream &os, const SetManagedByInterval &st) { if (st.interval.size() == 2) return os; auto it = next(st.interval.begin()); while (true) { os << '[' << it->first << ", " << it->second << ']'; it = next(it); if (next(it) == st.interval.end()) { break; } else { os << ' '; } } return os; } }; int main() { ll d; int q; cin >> d >> q; SetManagedByInterval st; ll ans = 0; while (q--) { ll a, b; cin >> a >> b; st.insert(a, b); auto [l, r] = *prev(st.interval.lower_bound({a + 1, a + 1})); chmax(ans, r - l + 1); cout << ans << '\n'; } return 0; }