#include #include #include #include #include #include #include #include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); ll d; int q; cin >> d >> q; map mp; ll l = 0; for (int i = 0; i < q; i++) { ll a, b; cin >> a >> b; b++; auto p = mp.lower_bound(a); if (p == mp.end() || b < p->second) { mp.insert(make_pair(b, a)); l = max(l, b - a); } else { auto t = make_pair(b, a); while (1) { t = make_pair(max(t.first, p->first), min(t.second, p->second)); auto g = p++; mp.erase(g); if (p == mp.end()) break; if (t.first < p->second) break; } mp.insert(t); l = max(l, t.first - t.second); } cout << l << '\n'; } return 0; }