1 #include <iostream>
2 #include <cstdio>
3 #include <algorithm>
4 using namespace std;
5 const int MAXN=50001;
6 struct Seg
7 {
8 int l,r,s,lazy,lx,rx,f;
9 }Tree[MAXN<<2];
10 int n;
11 void Make_Tree(int x,int l,int r)
12 {
13 Tree[x].l=l,Tree[x].r=r;
14 if(l==r) {
15 Tree[x].s=1;Tree[x].lazy=0;Tree[x].lx=Tree[x].rx=1;
16 Tree[x].f=1;
17 return;
18 }
19 int mid=(l+r)>>1;
20 Make_Tree(x<<1,l,mid);
21 Make_Tree(x<<1|1,mid+1,r);
22 Tree[x].s=Tree[x].r-Tree[x].l+1;
23 Tree[x].lx=Tree[x].rx=Tree[x].s;
24 }
25 void pushdown(int x)
26 {
27 int lc=x<<1,rc=x<<1|1;
28 if(Tree[x].f==1) {
29 Tree[x<<1].s=Tree[x<<1].lx=Tree[x<<1].rx=Tree[x<<1].r-Tree[x<<1].l+1;
30 Tree[x<<1|1].s=Tree[x<<1|1].lx=Tree[x<<1|1].rx=Tree[x<<1|1].r-Tree[x<<1|1].l+1;
31 Tree[x].f=0;Tree[x<<1].f=1,Tree[x<<1|1].f=1;
32 }
33 else if(Tree[x].f==2) {
34 Tree[x<<1].s=Tree[x<<1|1].s=0;
35 Tree[x<<1].lx=Tree[x<<1|1].lx=0;
36 Tree[x<<1].rx=Tree[x<<1|1].rx=0;
37 Tree[x].f=0;Tree[x<<1].f=2,Tree[x<<1|1].f=2;
38 }
39 }
40 void Modify(int x,int l,int r,int f)
41 {
42 //cout<<x<<‘ ‘<<l<<‘ ‘<<r<<Tree[x].s<<endl;
43 if(Tree[x].l==l&&Tree[x].r==r) {
44 if(f==1) Tree[x].s=Tree[x].lx=Tree[x].rx=r-l+1,Tree[x].f=1;
45 else if(f==2) Tree[x].s=Tree[x].lx=Tree[x].rx=0,Tree[x].f=2;
46 return;
47 }
48 int mid=(Tree[x].l+Tree[x].r)>>1;
49 pushdown(x);
50 if(r<=mid) Modify(x<<1,l,r,f);
51 else if(l>mid) Modify(x<<1|1,l,r,f);
52 else Modify(x<<1,l,mid,f),Modify(x<<1|1,mid+1,r,f);
53 Tree[x].s=max(Tree[x<<1].s,Tree[x<<1|1].s);
54 Tree[x].s=max(Tree[x].s,Tree[x<<1].rx+Tree[x<<1|1].lx);
55 Tree[x].lx=Tree[x<<1].lx;
56 if(Tree[x].lx==Tree[x<<1].r-Tree[x<<1].l+1) Tree[x].lx+=Tree[x<<1|1].lx;
57 Tree[x].rx=Tree[x<<1|1].rx;
58 if(Tree[x].rx==Tree[x<<1|1].r-Tree[x<<1|1].l+1) Tree[x].rx+=Tree[x<<1].rx;
59 // cout<<‘@‘<<Tree[x].s<<‘ ‘<<x<<‘@‘<<endl;
60 }
61 int Query(int x,int k)
62 {
63 if(Tree[x].l==Tree[x].r) return Tree[x].l;
64 pushdown(x);
65 int mid=(Tree[x].l+Tree[x].r)>>1;
66 if(Tree[x<<1].s>=k) return Query(x<<1,k);
67 else if(Tree[x<<1].rx+Tree[x<<1|1].lx>=k) return mid-Tree[x<<1].rx+1;
68 else return Query(x<<1|1,k);
69 }
70 void check()
71 {
72 int i,j;
73 for(i=1;i<=n*2;i++)
74 cout<<Tree[i].l<<" "<<Tree[i].r<<" "<<Tree[i].s<<" "<<Tree[i].lx<<" "<<Tree[i].rx<<" "<<Tree[i].f<<endl;
75 }
76 int main(int argc, char *argv[])
77 {
78 int i,j,op,x,y,m;
79 scanf("%d%d",&n,&m);
80 Make_Tree(1,1,n);
81 for(i=1;i<=m;i++)
82 {
83 scanf("%d",&op);
84 if(op==1) {
85 scanf("%d",&x);
86 if(Tree[1].s<x) printf("0\n");
87 else {
88 int ans=Query(1,x);
89 printf("%d\n",ans);
90 Modify(1,ans,ans+x-1,2);
91 }
92 }
93 else {
94 scanf("%d%d",&x,&y);
95 Modify(1,x,x+y-1,1);
96 }
97 }
98 return 0;
99 }