#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 500010;
int n,m,lnum[maxn],rnum[maxn],maxx[maxn],len[maxn],flag[maxn];
void pushup(int o)
{
lnum[o] = lnum[o * 2];
rnum[o] = rnum[o * 2 + 1];
if (lnum[o * 2] == len[o * 2])
lnum[o] += lnum[o * 2 + 1];
if (rnum[o * 2 + 1] == len[o * 2 + 1])
rnum[o] += rnum[o * 2];
maxx[o] = max(max(maxx[o * 2],maxx[o * 2 + 1]),rnum[o * 2] + lnum[o * 2 + 1]);
}
void build(int l,int r,int o)
{
len[o] = r - l + 1;
if (l == r)
{
lnum[o] = rnum[o] = maxx[o] = len[o];
return;
}
int mid = (l + r) >> 1;
build(l,mid,o * 2);
build(mid + 1,r,o * 2 + 1);
pushup(o);
}
void pushdown(int o)
{
if (flag[o] == 1)
{
lnum[o * 2] = rnum[o * 2] = maxx[o * 2] = len[o * 2];
lnum[o * 2 + 1] = rnum[o * 2 + 1] = maxx[o * 2 + 1] = len[o * 2 + 1];
flag[o * 2] = flag[o * 2 + 1] = flag[o];
}
else
if (flag[o] == 2)
{
lnum[o * 2] = rnum[o * 2] = maxx[o * 2] = lnum[o * 2 + 1] = rnum[o * 2 + 1] = maxx[o * 2 + 1] = 0;
flag[o * 2] = flag[o * 2 + 1] = flag[o];
}
flag[o] = 0;
}
void update(int l,int r,int o,int x,int y,int d)
{
if (x <= l && r <= y)
{
flag[o] = d + 1;
if (d == 0)
lnum[o] = rnum[o] = maxx[o] = len[o];
else
lnum[o] = rnum[o] = maxx[o] = 0;
return;
}
pushdown(o);
int mid = (l + r) >> 1;
if (x <= mid)
update(l,mid,o * 2,x,y,d);
if (y > mid)
update(mid + 1,r,o * 2 + 1,x,y,d);
pushup(o);
}
int find(int l,int r,int o,int d)
{
pushdown(o);
if (l == r)
return l;
int mid = (l + r) >> 1;
if (maxx[o * 2] >= d)
return find(l,mid,o * 2,d);
if (rnum[o * 2] + lnum[o * 2 + 1] >= d)
return mid - rnum[o * 2] + 1;
return find(mid + 1,r,o * 2 + 1,d);
}
int main()
{
scanf("%d%d",&n,&m);
build(1,n,1);
for (int i = 1; i <= m; i++)
{
int op,x,d;
scanf("%d",&op);
if (op == 1)
{
scanf("%d",&d);
//printf("%d\n",maxx[1]);
if (maxx[1] >= d)
{
int cur = find(1,n,1,d);
printf("%d\n",cur);
update(1,n,1,cur,cur + d - 1,1);
}
else
printf("0\n");
}
else
{
scanf("%d%d",&x,&d);
update(1,n,1,x,x + d - 1,0);
}
}
return 0;
}