1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 using namespace std;
7 #define Maxn 300010
8 #define INF 0x7fffffff
9
10 int nl[Maxn],nr[Maxn],nn[Maxn*2];
11
12 struct node
13 {
14 int l,r,lc,rc,mn,lazy;
15 int id;
16 }tr[Maxn*2];
17
18 int rt[Maxn*2];
19 int rtt(int x)
20 {
21 if(rt[x]!=x) rt[x]=rtt(rt[x]);
22 return rt[x];
23 }
24
25 int len=0;
26 int build(int l,int r)
27 {
28 int x=++len;
29 tr[x].l=l;tr[x].r=r;
30 if(l!=r)
31 {
32 int mid=(l+r)>>1;
33 tr[x].lc=build(l,mid);
34 tr[x].rc=build(mid+1,r);
35 tr[x].lazy=0;
36 int lc=tr[x].lc,rc=tr[x].rc;
37 if(tr[lc].mn<=tr[rc].mn) tr[x].mn=tr[lc].mn,tr[x].id=tr[lc].id;
38 else tr[x].mn=tr[rc].mn,tr[x].id=tr[rc].id;
39 }
40 else tr[x].lc=tr[x].rc=0,tr[x].mn=nn[nr[l]]-nn[nl[l]],tr[x].id=l;
41 return x;
42 }
43
44 void upd(int x)
45 {
46 if(tr[x].l==tr[x].r) return;
47 int lc=tr[x].lc,rc=tr[x].rc;
48 if(tr[lc].mn!=INF) tr[lc].mn-=tr[x].lazy;
49 if(tr[rc].mn!=INF) tr[rc].mn-=tr[x].lazy;
50 tr[lc].lazy+=tr[x].lazy;
51 tr[rc].lazy+=tr[x].lazy;
52 tr[x].lazy=0;
53 }
54
55 void change(int x,int y,int p)
56 {
57 if(tr[x].mn==INF) return;
58 int mid=(tr[x].l+tr[x].r)>>1,lc=tr[x].lc,rc=tr[x].rc;
59 if(p)
60 {
61 if(nl[tr[x].l]<=y&&y<nr[tr[x].l]&&nl[tr[x].r]<=y&&y<nr[tr[x].r])
62 {
63 tr[x].lazy+=nn[y+1]-nn[y];
64 tr[x].mn-=nn[y+1]-nn[y];
65 return;
66 }
67 if(tr[x].l==tr[x].r) return;
68 upd(x);
69 if(y<nr[mid]) change(lc,y,p);
70 if(nl[mid+1]<=y) change(rc,y,p);
71 }
72 else
73 {
74 if(tr[x].l==tr[x].r)
75 {
76 tr[x].mn=INF;
77 return;
78 }
79 upd(x);
80 if(y<=mid) change(tr[x].lc,y,p);
81 else change(tr[x].rc,y,p);
82 }
83 if(tr[lc].mn<=tr[rc].mn) tr[x].mn=tr[lc].mn,tr[x].id=tr[lc].id;
84 else tr[x].mn=tr[rc].mn,tr[x].id=tr[rc].id;
85 }
86
87
88 struct nnode{int x,id;}t[Maxn*2];
89 bool cmp(nnode x,nnode y) {return x.x<y.x;}
90
91 int main()
92 {
93 int mx,n;
94 scanf("%d%d",&mx,&n);
95 for(int i=1;i<=n;i++) {scanf("%d%d",&nl[i],&nr[i]);
96 t[i*2-1].x=nl[i];t[i*2-1].id=i;t[i*2].x=nr[i];t[i*2].id=-i;}
97 sort(t+1,t+1+2*n,cmp);
98 mx=1;nl[t[1].id]=1;nn[1]=t[1].x;
99 for(int i=2;i<=2*n;i++)
100 {
101 if(t[i].x!=t[i-1].x) mx++,nn[mx]=t[i].x;
102 if(t[i].id>0) nl[t[i].id]=mx;
103 else nr[-t[i].id]=mx;
104 }
105 build(1,n);
106 for(int i=1;i<=mx;i++) rt[i]=i;
107 for(int i=1;i<=n;i++)
108 {
109 int x=tr[1].id;
110 printf("%d\n",x);
111 change(1,x,0);
112 int st=rtt(nl[x]);
113 for(int j=st;j<nr[x];)
114 {
115 change(1,j,1);
116 rt[j]=rtt(j+1);
117 j=rt[j];
118 }
119 }
120 return 0;
121 }