#define ls id << 1
#define rs id << 1 | 1
#define Mid int mid = (l + r) >> 1
const int N = 5e4 + 5;
struct SegTree {
int sum, len;
int lmax, rmax;
int tag;
#define sum(x) Tree[x].sum
#define len(x) Tree[x].len
#define tag(x) Tree[x].tag
#define lm(x) Tree[x].lmax
#define rm(x) Tree[x].rmax
} Tree[N << 2];
int n, m;
void pushup(int id) {
lm(id) = (lm(ls) == len(ls)) ? len(ls) + lm(rs) : lm(ls);
rm(id) = (rm(rs) == len(rs)) ? len(rs) + rm(ls) : rm(rs);
sum(id) = max(lm(ls), max(rm(rs), rm(ls) + lm(rs)));
}
void pushdown(int id) {
if(tag(id)) {
tag(ls) = tag(rs) = tag(id);
tag(id) == 1 ? sum(ls) = lm(ls) = rm(ls) = len(ls), sum(rs) = lm(rs) = rm(rs) = len(rs) : sum(ls) = lm(ls) = rm(ls) = sum(rs) = lm(rs) = rm(rs) = 0;
tag(id) = 0;
}
}
void build(int id, int l, int r) {
sum(id) = len(id) = lm(id) = rm(id) = r - l + 1;
if(l == r) return ;
Mid;
build(ls, l, mid);
build(rs, mid + 1, r);
}
void modify(int id, int l, int r, int x, int y) {
if(x <= l && r <= y) {
sum(id) = lm(id) = rm(id) = len(id);
tag(id) = 1;
return ;
}
pushdown(id);
Mid;
if(mid >= x) modify(ls, l, mid, x, y);
if(mid < y) modify(rs, mid + 1, r, x, y);
pushup(id);
}
void update(int id, int l, int r, int x, int y) {
if(x <= l && r <= y) {
sum(id) = lm(id) = rm(id) = 0;
tag(id) = 2;
return ;
}
pushdown(id);
Mid;
if(mid >= x) update(ls, l, mid, x, y);
if(mid < y) update(rs, mid + 1, r, x, y);
pushup(id);
}
int query(int id, int l, int r, int x) {
if(l == r) return l;
pushdown(id);
Mid;
if(sum(ls) >= x) return query(ls, l, mid, x);
if(rm(ls) + lm(rs) >= x) return mid - rm(ls) + 1;
return query(rs, mid + 1, r, x);
}
int main() {
qread(n, m);
build(1, 1, n);
W(m) {
int op, x, y;
qread(op, x);
if(op == 1) {
if(sum(1) >= x) {
y = query(1, 1, n, x);
printf("%d\n", y);
update(1, 1, n, y, y + x - 1);
}
else puts("0");
}
else {
qread(y);
modify(1, 1, n, x, x + y - 1);
}
}
return 0;
}