#include #define rep(i,j,n) for(ll i=j;i<(ll)(n);i++) #define rrep(i,j,n) for(ll i=j;i>=n;i--) #define all(x) (x).begin(),(x).end() #define m0(x) memset(x,0,sizeof(x)) #define pb push_back #define mp make_pair #define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c))) #define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()) using namespace std; typedef long long ll; typedef long double ld; template bool chmax(T &a, const T &b){if(a bool chmin(T &a, const T &b){if(a>b) {a=b;return 1;}return 0;} ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} ll max(ll a,ll b){return a>b?a:b;} ll min(ll a,ll b){return a struct interval_set{ interval_set(){} void insert(T l,T r){ st.insert(mp(l,r)); auto iter = st.find(make_pair(l,r)); vector> erase_vec; T left = l,right = r; for(auto iter_ = iter;iter_ != st.end();iter_++){ if(right < iter_->first) break; erase_vec.push_back(*iter_); right = max(right,iter_->second); } for(auto iter_ = iter;;iter_--){ if(iter_->second < left) break; erase_vec.push_back(*iter_); left = min(left,iter_->first); if(iter_ == st.begin()) break; } for(auto _ : erase_vec){ auto iter_ = st.find(_); if(iter_ != st.end()) st.erase(iter_); } st.insert(mp(left,right)); chmax(max_len,right - left + 1); } T max_length(){ return max_len; } set> st; T max_len = 0; }; void solve(){ 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() - 1 << endl; } } int main(){ cin.tie(nullptr); cout << fixed << setprecision(20); ll T; T = 1; /* cin >> T; */ while(T--) solve(); }