#include <stdio.h>
#include <vector>
#include <iostream>
using namespace std;
struct node {
int sum;
node *left, *right;
node(int low, int high)
{
sum = (high - low + 1);
left = NULL;
right = NULL;
}
void extend(int l, int r)
{
if (left == NULL) {
int mid = (l + r) >> 1;
left = new node(l, mid);
right = new node(mid + 1, r);
}
}
};
node* Root;
void updateSegTree(int index, int delta, node* root, int l, int r)
{
if (index < l || index > r)
return;
if (l == r) {
root->sum += delta;
return;
}
root->extend(l, r);
updateSegTree(index, delta, root->left, l, (l+r) / 2);
updateSegTree(index, delta, root->right, (l+r) / 2 + 1, r);
root->sum = (root->left)->sum + (root->right)->sum;
}
int query(int k, node* root, int l, int r)
{
if (l == r)
return l;
root->extend(l, r);
if ((root->left)->sum >= k)
return query(k, root->left, l, (l+r)/2);
return query(k - ((root->left)->sum), root->right, (l+r)/2+1, r);
}
int main()
{
//std::cerr << sizeof(node) << std::endl;
int n, m, num;
char op;
scanf("%d%d", &n, &m);
Root = new node(1, n);
for (int i = 1; i <= m; i++) {
scanf(" %c %d", &op, &num);
int q = query(num, Root, 1, n);
if (op == 'L')
printf("%d\n", q);
else
updateSegTree(q, -1, Root, 1, n);
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxpb3N0cmVhbT4KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3Qgbm9kZSB7CiAgICBpbnQgc3VtOwogICAgbm9kZSAqbGVmdCwgKnJpZ2h0OwoKICAgIG5vZGUoaW50IGxvdywgaW50IGhpZ2gpCiAgICB7CiAgICAgICAgc3VtID0gKGhpZ2ggLSBsb3cgKyAxKTsKICAgICAgICBsZWZ0ID0gTlVMTDsKICAgICAgICByaWdodCA9IE5VTEw7CiAgICB9CgogICAgdm9pZCBleHRlbmQoaW50IGwsIGludCByKQogICAgewogICAgICAgIGlmIChsZWZ0ID09IE5VTEwpIHsKICAgICAgICAgICAgaW50IG1pZCA9IChsICsgcikgPj4gMTsKICAgICAgICAgICAgbGVmdCA9IG5ldyBub2RlKGwsIG1pZCk7CiAgICAgICAgICAgIHJpZ2h0ID0gbmV3IG5vZGUobWlkICsgMSwgcik7CiAgICAgICAgfQogICAgfQp9OwoKbm9kZSogUm9vdDsKCnZvaWQgdXBkYXRlU2VnVHJlZShpbnQgaW5kZXgsIGludCBkZWx0YSwgbm9kZSogcm9vdCwgaW50IGwsIGludCByKQp7CiAgICBpZiAoaW5kZXggPCBsIHx8IGluZGV4ID4gcikKICAgICAgICByZXR1cm47CgogICAgaWYgKGwgPT0gcikgewogICAgICAgIHJvb3QtPnN1bSArPSBkZWx0YTsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgcm9vdC0+ZXh0ZW5kKGwsIHIpOwogICAgdXBkYXRlU2VnVHJlZShpbmRleCwgZGVsdGEsIHJvb3QtPmxlZnQsIGwsIChsK3IpIC8gMik7CiAgICB1cGRhdGVTZWdUcmVlKGluZGV4LCBkZWx0YSwgcm9vdC0+cmlnaHQsIChsK3IpIC8gMiArIDEsIHIpOwogICAgcm9vdC0+c3VtID0gKHJvb3QtPmxlZnQpLT5zdW0gKyAocm9vdC0+cmlnaHQpLT5zdW07Cn0KCmludCBxdWVyeShpbnQgaywgbm9kZSogcm9vdCwgaW50IGwsIGludCByKQp7CiAgICBpZiAobCA9PSByKQogICAgICAgIHJldHVybiBsOwoKICAgIHJvb3QtPmV4dGVuZChsLCByKTsKICAgIGlmICgocm9vdC0+bGVmdCktPnN1bSA+PSBrKQogICAgICAgIHJldHVybiBxdWVyeShrLCByb290LT5sZWZ0LCBsLCAobCtyKS8yKTsKICAgIHJldHVybiBxdWVyeShrIC0gKChyb290LT5sZWZ0KS0+c3VtKSwgcm9vdC0+cmlnaHQsIChsK3IpLzIrMSwgcik7Cn0KCmludCBtYWluKCkKewogICAgLy9zdGQ6OmNlcnIgPDwgc2l6ZW9mKG5vZGUpIDw8IHN0ZDo6ZW5kbDsKICAgIGludCBuLCBtLCBudW07C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