#include <cstdio>
#include <algorithm>
using namespace std;
char buf[10000000], *ptr = buf - 1;
inline int readint(){
int n = 0;
char ch = *++ptr;
while(ch < ‘0‘ || ch > ‘9‘) ch = *++ptr;
while(ch <= ‘9‘ && ch >= ‘0‘){
n = (n << 1) + (n << 3) + ch - ‘0‘;
ch = *++ptr;
}
return n;
}
const int maxn = 50000 + 10;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
int n, m;
int mx[maxn << 2], lx[maxn << 2], rx[maxn << 2], tag[maxn << 2];
inline void PushDown(int rt, int l, int r){
if(tag[rt] == 1){
mx[rt << 1] = lx[rt << 1] = rx[rt << 1] = mx[rt << 1 | 1] = lx[rt << 1 | 1] = rx[rt << 1 | 1] = 0;
tag[rt << 1] = tag[rt << 1 | 1] = 1;
tag[rt] = -1;
}
if(tag[rt] == 0){
int mid = l + r >> 1;
mx[rt << 1] = lx[rt << 1] = rx[rt << 1] = mid - l + 1;
mx[rt << 1 | 1] = lx[rt << 1 | 1] = rx[rt << 1 | 1] = r - mid;
tag[rt << 1] = tag[rt << 1 | 1] = 0;
tag[rt] = -1;
}
}
inline void PushUp(int rt, int l, int r){
int mid = l + r >> 1;
if(lx[rt << 1] == mid - l + 1) lx[rt] = lx[rt << 1] + lx[rt << 1 | 1];
else lx[rt] = lx[rt << 1];
if(rx[rt << 1 | 1] == r - mid) rx[rt] = rx[rt << 1 | 1] + rx[rt << 1];
else rx[rt] = rx[rt << 1 | 1];
mx[rt] = max(mx[rt << 1], max(mx[rt << 1 | 1], rx[rt << 1] + lx[rt << 1 | 1]));
}
inline int Query(int d){
int rt = 1, l = 1, r = n;
while(1){
PushDown(rt, l, r);
if(mx[rt] < d) return 0;
if(lx[rt] >= d) return l;
int mid = l + r >> 1;
if(mx[rt << 1] >= d){
r = mid;
rt = rt << 1;
}
else if(rx[rt << 1] && rx[rt << 1] + lx[rt << 1 | 1] >= d) return mid - rx[rt << 1] + 1;
else{
l = mid + 1;
rt = rt << 1 | 1;
}
}
}
void Change(int ql, int qr, int qw, int l, int r, int rt){
if(ql <= l && r <= qr){
tag[rt] = qw;
if(qw == 0) mx[rt] = lx[rt] = rx[rt] = r - l + 1;
else mx[rt] = lx[rt] = rx[rt] = 0;
}
else{
PushDown(rt, l, r);
int mid = l + r >> 1;
if(ql <= mid) Change(ql, qr, qw, lson);
if(qr > mid) Change(ql, qr, qw, rson);
PushUp(rt, l, r);
}
}
int main(){
fread(buf, sizeof(char), sizeof(buf), stdin);
n = readint();
m = readint();
tag[1] = 0;
mx[1] = lx[1] = rx[1] = n;
for(int opt, x, y, i = 1; i <= m; i++){
opt = readint();
x = readint();
if(opt == 1){
y = Query(x);
printf("%d\n", y);
if(y) Change(y, y + x - 1, 1, 1, n, 1);
}
else{
y = readint();
Change(x, x + y - 1, 0, 1, n, 1);
}
}
return 0;
}