#include<iostream>#include<stdio.h>#include<string.h>#include<cmath>#define L(x) (x<<1)#define R(x) (x<<1 |1)#define MAX 50010using namespace std;struct node{ int l,r,cover,room,lroom,rroom;}a[MAX*3];void build(int t,int l,int r){ a[t].l=l; a[t].r=r; a[t].cover=0; a[t].room=r-l; a[t].lroom=r-l; a[t].rroom=r-l; if(r-l==1)return ; int mid=(l+r)/2; build(L(t),l,mid); build(R(t),mid,r);}int query(int t,int val){ if(a[t].cover==0&&a[t].room>=val) return a[t].l; if(a[t].cover==1||a[t].room<val) return 0; if(a[L(t)].room>=val) return query(L(t),val); if(a[L(t)].rroom+a[R(t)].lroom>=val) return a[L(t)].r-a[L(t)].rroom; if(a[R(t)].room>=val) return query(R(t),val);}void uproom(int t){ if(a[t].cover==1) { a[t].room=0; a[t].lroom=0; a[t].rroom=0; return ; } if(a[t].cover==0) { a[t].room=a[t].r-a[t].l; a[t].lroom=a[t].room; a[t].rroom=a[t].room; return ; }}void update(int t,int l,int r,int cover){ if(a[t].cover==cover)return ; if(l<=a[t].l&&a[t].r<=r) { a[t].cover=cover; uproom(t); return ; } if(a[t].r-a[t].l==1) return; if(a[t].cover!=-1) { a[L(t)].cover=a[t].cover; a[R(t)].cover=a[t].cover; a[t].cover=-1; uproom(R(t)); uproom(L(t)); } int mid=(a[t].l+a[t].r)/2; if(l<=mid) update(L(t),l,r,cover); if(r>mid) update(R(t),l,r,cover); if(a[L(t)].cover==0&&a[R(t)].cover==0) a[t].cover=0; else if(a[L(t)].cover==1&&a[R(t)].cover==1) a[t].cover=1; else a[t].cover=-1; a[t].lroom=a[L(t)].lroom+(a[L(t)].cover==0?a[R(t)].lroom:0); a[t].rroom=a[R(t)].rroom+(a[R(t)].cover==0?a[L(t)].rroom:0); a[t].room=max(max(a[L(t)].room,a[R(t)].room),a[R(t)].lroom+a[L(t)].rroom);}int main(){ int n,m,i,x,y; int q; while(scanf("%d%d",&n,&m)!=EOF) { build(1,1,n+1); for(i=0;i<m;i++) { scanf("%d",&x); if(x==1) { scanf("%d",&y); q=query(1,y); if(q==0) printf("0\n"); else { printf("%d\n",q); update(1,q,q+y,1); } } else { scanf("%d%d",&x,&y); update(1,x,x+y,0); } } }}