# include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int inf = (int)1e9 + 7;
const int maxn = (int)6e5 + 7;
const int lmaxn = (int)2e6 + 7;
const ll linf = (ll)1e16 + 7;
const ld eps = ld(1e-11);
const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};
struct node{
node *l, *r;
ll val;
node(){
l = r = nullptr;
val = 0;
}
~node(){}
};
struct tree{
node *root;
tree(){
root = new node();
}
void upd(node *&v, ll tl, ll tr, ll pos, ll val){
if(tl == tr){
v -> val = val;
return;
}
ll tm = (tl + tr) >> 1ll;
if(v -> l == nullptr) v -> l = new node();
if(v -> r == nullptr) v -> r = new node();
if(pos <= tm)
upd(v -> l, tl, tm, pos, val);
else
upd(v -> r, tm + 1, tr, pos, val);
v -> val = (v -> l) -> val + (v -> r) -> val;
}
ll get(node *&v, ll tl, ll tr, ll k){
ll tm = (tl + tr) >> 1ll;
if(tl == tr)
return tl;
if((v -> l) == nullptr) v -> l = new node();
if((v -> r) == nullptr) v -> r = new node();
ll le = (tm - tl + 1) - ((v -> l) -> val);
if(k <= le)
return get(v -> l, tl, tm, k);
else
return get(v -> r, tm + 1, tr, k - le);
}
}tr;
ll n, q;
int main(){
scanf("%lld %lld", &n, &q);
for(ll i = 1; i <= q; ++i){
char t;
scanf(" %c", &t);
if(t == 'D'){
ll x;
scanf("%lld", &x);
x = tr.get(tr.root, 1, n, x);
tr.upd(tr.root, 1, n, x, 1);
}
else{
ll x;
scanf("%lld", &x);
printf("%lld\n", tr.get(tr.root, 1, n, x));
}
}
return 0;
}
IyBpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgcGlpIHBhaXI8aW50LCBpbnQ+CiNkZWZpbmUgcGxsIHBhaXI8bGw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T0gbnVsbHB0cikgdiAtPiByID0gbmV3IG5vZGUoKTsKICAgICAgICBpZihwb3MgPD0gdG0pCiAgICAgICAgICAgIHVwZCh2IC0+IGwsIHRsLCB0bSwgcG9zLCB2YWwpOwogICAgICAgIGVsc2UKICAgICAgICAgICAgdXBkKHYgLT4gciwgdG0gKyAxLCB0ciwgcG9zLCB2YWwpOwogICAgICAgIHYgLT4gdmFsID0gKHYgLT4gbCkgLT4gdmFsICsgKHYgLT4gcikgLT4gdmFsOwogICAgfQogICAgbGwgZ2V0KG5vZGUgKiZ2LCBsbCB0bCwgbGwgdHIsIGxsIGspewogICAgICAgIGxsIHRtID0gKHRsICsgdHIpID4+IDFsbDsKICAgICAgICBpZih0bCA9PSB0cikKICAgICAgICAgICAgcmV0dXJuIHRsOwogICAgICAgIGlmKCh2IC0+IGwpID09IG51bGxwdHIpIHYgLT4gbCA9IG5ldyBub2RlKCk7CiAgICAgICAgaWYoKHYgLT4gcikgPT0gbnVsbHB0cikgdiAtPiByID0gbmV3IG5vZGUoKTsKCiAgICAgICAgbGwgbGUgPSAodG0gLSB0bCArIDEpIC0gKCh2IC0+IGwpIC0+IHZhbCk7CiAgICAgICAgaWYoayA8PSBsZSkKICAgICAgICAgICAgcmV0dXJuIGdldCh2IC0+IGwsIHRsLCB0bSwgayk7CiAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gZ2V0KHYgLT4gciwgdG0gKyAxLCB0ciwgayAtIGxlKTsKICAgIH0KfXRyOwoKbGwgbiwgcTsKCmludCBtYWluKCl7CiAgICBzY2FuZigiJWxsZCAlbGxkIiwgJm4sICZxKTsKICAgIGZvcihsbCBpID0gMTsgaSA8PSBxOyArK2kpewogICAgICAgIGNoYXIgdDsKICAgICAgICBzY2FuZigiICVjIiwgJnQpOwogICAgICAgIGlmKHQgPT0gJ0QnKXsKICAgICAgICAgICAgbGwgeDsKICAgICAgICAgICAgc2NhbmYoIiVsbGQiLCAmeCk7CiAgICAgICAgICAgIHggPSB0ci5nZXQodHIucm9vdCwgMSwgbiwgeCk7CiAgICAgICAgICAgIHRyLnVwZCh0ci5yb290LCAxLCBuLCB4LCAxKTsKICAgICAgICB9CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgbGwgeDsKICAgICAgICAgICAgc2NhbmYoIiVsbGQiLCAmeCk7CiAgICAgICAgICAgIHByaW50ZigiJWxsZFxuIiwgdHIuZ2V0KHRyLnJvb3QsIDEsIG4sIHgpKTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gMDsKfQ==