#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#define N 50005
using namespace std;
int n,m;
int lc[4*N],rc[4*N],mx[4*N],len[4*N],l[4*N],r[4*N],tag[4*N];
inline int read()
{
int a=0,f=1; char c=getchar();
while (c<‘0‘||c>‘9‘) {if (c==‘0‘) f=-1; c=getchar();}
while (c>=‘0‘&&c<=‘9‘) {a=a*10+c-‘0‘; c=getchar();}
return a*f;
}
inline void pushup(int k)
{
if (mx[k<<1]==len[k<<1]&&mx[k<<1|1]==len[k<<1|1]) lc[k]=rc[k]=mx[k]=len[k];
else if (mx[k<<1]==len[k<<1]) {lc[k]=mx[k]=len[k<<1]+lc[k<<1|1]; rc[k]=rc[k<<1|1];}
else if (mx[k<<1|1]==len[k<<1|1]) {rc[k]=mx[k]=len[k<<1|1]+rc[k<<1]; lc[k]=lc[k<<1];}
else
{
lc[k]=lc[k<<1]; rc[k]=rc[k<<1|1];
mx[k]=max(mx[k<<1],mx[k<<1|1]);
mx[k]=max(mx[k],rc[k<<1]+lc[k<<1|1]);
}
}
inline void pushdown(int k)
{
if (tag[k]==-1||l[k]==r[k]) return;
tag[k<<1]=tag[k<<1|1]=tag[k];
lc[k<<1]=rc[k<<1]=mx[k<<1]=(tag[k]==0?len[k<<1]:0);
lc[k<<1|1]=rc[k<<1|1]=mx[k<<1|1]=(tag[k]==0?len[k<<1|1]:0);
tag[k]=-1;
}
void change(int k,int x,int y,int z)
{
pushdown(k);
if (l[k]==x&&r[k]==y)
{
lc[k]=rc[k]=mx[k]=(z==0?len[k]:0);
tag[k]=z;
return;
}
int mid=(l[k]+r[k])>>1;
if (y<=mid) change(k<<1,x,y,z);
else if (mid<x) change(k<<1|1,x,y,z);
else
{
change(k<<1,x,mid,z);
change(k<<1|1,mid+1,y,z);
}
pushup(k);
}
void build(int k,int x,int y)
{
l[k]=x; r[k]=y; lc[k]=rc[k]=mx[k]=len[k]=y-x+1; tag[k]=-1;
if (x==y) return;
int mid=(l[k]+r[k])>>1;
build(k<<1,x,mid); build(k<<1|1,mid+1,y);
}
inline int ask(int k,int d)
{
pushdown(k);
if (l[k]==r[k])return l[k];
int mid=(l[k]+r[k])>>1;
if (mx[k<<1]>=d) return ask(k<<1,d);
if (rc[k<<1]+lc[k<<1|1]>=d)
return mid-rc[k<<1]+1;
return ask(k<<1|1,d);
}
int main()
{
n=read(); m=read();
build(1,1,n);
while (m--)
{
int tmp=read(),x,d,t;
if (tmp==1) {d=read(); if (mx[1]<d) puts("0"); else {t=ask(1,d); printf("%d\n",t); change(1,t,t+d-1,1);}}
if (tmp==2) {x=read(); d=read(); change(1,x,x+d-1,0);}
}
return 0;
}