#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MAXN (1 << 20)
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct node
{
long long cnt;
long long left, right, id;
node() {left = -1, right = -1, id = -1; cnt = 0;}
};
node broken;
struct dynamic_segment_tree
{
long long cnt;
node tr[MAXN];
long long newnode()
{
tr[cnt].id = cnt;
return cnt++;
}
void expand(long long idx, long long lb, long long rb)
{
long long mid = (lb + rb) >> 1;
if(tr[idx].left == -1)
{
tr[idx].left = newnode();
tr[tr[idx].left].cnt = (mid - lb + 1);
}
if(tr[idx].right == -1)
{
tr[idx].right = newnode();
tr[tr[idx].right].cnt = (rb - mid);
}
}
void init()
{
cnt = 0;
tr[0].id = newnode();
}
node merge(node l, node r)
{
node ret;
ret.cnt = l.cnt + r.cnt;
return ret;
}
void update(long long idx)
{
tr[idx].cnt = tr[tr[idx].left].cnt + tr[tr[idx].right].cnt;
}
long long query(long long k, long long l, long long r, long long idx)
{
if(l == r)
return l;
long long mid = (l + r) >> 1;
expand(idx, l, r);
//printf("[%lld, %lld] : %lld, --> %lld, %lld\n", l, r, k, tr[tr[idx].left].cnt,
//tr[tr[idx].right].cnt);
if(tr[tr[idx].left].cnt >= k) return query(k, l, mid, tr[idx].left);
else return query(k - tr[tr[idx].left].cnt, mid + 1, r, tr[idx].right);
}
void update(long long pos, long long val, long long l, long long r, long long idx)
{
if(l > pos || r < pos)
return;
if(l == r && l == pos)
{
tr[idx].cnt += val;
return;
}
long long mid = (l + r) >> 1;
expand(idx, l, r);
//printf("[%lld, %lld] : %lld, --> %lld, %lld\n", l, r, idx, tr[tr[idx].left].cnt,
//tr[tr[idx].right].cnt);
update(pos, val, l, mid, tr[idx].left);
update(pos, val, mid + 1, r, tr[idx].right);
update(idx);
}
};
long long N;
void read()
{
scanf("%lld", &N);
}
dynamic_segment_tree t;
void solve()
{
t.init();
long long Q;
scanf("%lld", &Q);
while(Q--)
{
char type[2];
long long pos;
scanf("%s %lld", &type, &pos);
long long val = t.query(pos, 1, N, 0);
if(type[0] == 'D')
t.update(val, -1, 1, N, 0);
else
printf("%lld\n", val);
}
}
int main()
{
read();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlIDxleHQvcGJfZHMvYXNzb2NfY29udGFpbmVyLmhwcD4KI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CgojZGVmaW5lIE1BWE4gKDEgPDwgMjApCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp1c2luZyBuYW1lc3BhY2UgX19nbnVfcGJkczsKCnRlbXBsYXRlIDx0eXBlbmFtZSBUPiB1c2luZyBvcmRlcmVkX3NldCA9IHRyZWU8VCwgbnVsbF90eXBlLCBsZXNzPFQ+LCByYl90cmVlX3RhZywgdHJlZV9vcmRlcl9zdGF0aXN0aWNzX25vZGVfdXBkYXRlPjsKCnN0cnVjdCBub2RlCnsKCWxvbmcgbG9uZyBjbnQ7Cglsb25nIGxvbmcgbGVmdCwgcmlnaHQsIGlkOwoKCW5vZGUoKSB7bGVmdCA9IC0xLCByaWdodCA9IC0xLCBpZCA9IC0xOyBjbnQgPSAwO30KfTsKCm5vZGUgYnJva2VuOwoKc3RydWN0IGR5bmFtaWNfc2VnbWVudF90cmVlCnsKCWxvbmcgbG9uZyBjbnQ7Cglub2RlIHRyW01BWE5dOwoKCWxvbmcgbG9uZyBuZXdub2RlKCkKCXsJCgkJdHJbY250XS5pZCA9IGNudDsKCQlyZXR1cm4gY250Kys7Cgl9CgoJdm9pZCBleHBhbmQobG9uZyBsb25nIGlkeCwgbG9uZyBsb25nIGxiLCBsb25nIGxvbmcgcmIpCgl7CgkJbG9uZyBsb25nIG1pZCA9IChsYiArIHJiKSA+PiAxOwoKCQlpZih0cltpZHhdLmxlZnQgPT0gLTEpCgkJewoJCQl0clt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