#include #define rep(i,j,n) for(ll i=j;i<(ll)(n);i++) using namespace std; typedef long long ll; struct interval_set{ interval_set(){ st.insert(make_pair(-(1LL << 60),-(1LL << 60))); st.insert(make_pair(1LL << 60,1LL << 60)); } void insert(ll l,ll r){ auto iter = st.lower_bound(make_pair(l,r)); vector> erase_vec; ll left = l,right = r; for(auto iter_ = iter;;iter_++){ if(max(iter_->first,left) > min(iter_->second,right)) break; erase_vec.push_back(*iter_); left = min(left,iter_->first); right = max(right,iter_->second); } iter--; for(auto iter_ = iter;;iter_--){ if(max(iter_->first,left) > min(iter_->second,right)) break; erase_vec.push_back(*iter_); left = min(left,iter_->first); right = max(right,iter_->second); } for(auto _ : erase_vec) st.erase(_); st.insert(make_pair(left,right)); max_len = max(max_len,right - left); } ll max_length(){ return max_len; } set> st; ll max_len = 0; }; int main(){ cin.tie(nullptr); cout << fixed << setprecision(20); ll d,q; cin >> d >> q; vector a(q),b(q); rep(i,0,q) cin >> a[i] >> b[i]; interval_set is; rep(i,0,q){ is.insert(a[i],b[i]+1); cout << is.max_length() << endl; } }