void main(){ import std.stdio, std.string, std.conv, std.algorithm; long d; int q; rd(d, q); import std.typecons; alias Query=Tuple!(long, "a", long, "b"); auto queries=new Query[](q); long[] vals; foreach(i; 0..q){ long a, b; rd(a, b); queries[i]=Query(a, b+1); vals~=queries[i].a; vals~=queries[i].b; } sort(vals); int[long] map; foreach(val; vals){ if((val in map)==null) map[val]=map.length.to!(int); } long[int] rev; foreach(long k; map.keys){ rev[map[k]]=k; } // writeln(map); auto tree=new SquareRootDecompotision(map.length.to!(int)); long mx=0; foreach(query; queries){ int l=map[query.a], r=map[query.b]; tree.merge(l, r); long ol=rev[tree.getLeft(l)], or=rev[tree.getRight(l)]; mx=max(mx, or-ol); // writeln(ol, " ", or); writeln(mx); // tree.show; } } class SquareRootDecompotision{ int D=1; int[] st, ed; int[] buc_st, buc_ed; import std.algorithm; this(int n){ while(D*D=0) chmin(l, buc_st[left/D]); if(buc_st[right/D]>=0) chmax(r, buc_ed[right/D]); if(left-1>=0){ if(st[left-1]=0) chmin(l, buc_st[(left-1)/D]); } int bl=l/D, br=r/D; if(br-bl<=1){ eachFill(l, r, l, r); }else{ eachFill(l, (bl+1)*D, l, r); buc_st[(bl+1)..br]=l; buc_ed[(bl+1)..br]=r; eachFill(br*D, r, l, r); } } void eachFill(int tl, int tr, int l, int r){ // j in [tl, tr) st[j]<-l, ed[j]<-r push(tl/D); push(tr/D); // import std.stdio; // writeln(tl, " ", tr, " ", l, " ", r); foreach(int j; tl..tr) st[j]=l, ed[j]=r; } void push(int k){ if(buc_st[k]>=0) st[k*D..(k+1)*D]=buc_st[k]; if(buc_ed[k]>=0) ed[k*D..(k+1)*D]=buc_ed[k]; buc_st[k]=buc_ed[k]=-1; } int getLeft(int i){ int l=i; if(buc_st[i/D]>=0){ l=min(l, buc_st[i/D]); }else{ l=min(l, st[i]); } return l; } int getRight(int i){ int r=i; if(buc_ed[i/D]>=0){ r=max(r, buc_ed[i/D]); }else{ r=max(r, ed[i]); } return r; } void show(){ import std.stdio; writeln(st); writeln(buc_st); writeln(ed); writeln(buc_ed); } } void chmin(T)(ref T l, T r){if(l>r)l=r;} void chmax(T)(ref T l, T r){if(l