#include <iostream>
using namespace std;
struct vertex
{
vertex *left,*right;
short num;
};
struct sg_tree
{
static const int MPOW=31;
static const int N=1ll<<MPOW-1;
vertex arr[180000];
int sz;
sg_tree():sz(1)
{
arr[0].left=0;
arr[0].right=0;
arr[0].num=0;
}
void add(vertex *c,int cl,int cr,int x)
{
if(cl==cr)
c->num=1;
else
{
int cm=(cl+cr)>>1;
if(x<=cm)
{
if(c->left==0)
{
c->left=arr+sz;
arr[sz].right=0;
arr[sz].left=0;
sz++;
}
add(c->left,cl,cm,x);
}
else
{
if(c->right==0)
{
c->right=arr+sz;
arr[sz].right=0;
arr[sz].left=0;
sz++;
}
add(c->right,cm+1,cr,x);
}
c->num=0;
if(c->left!=0)
c->num+=c->left->num;
if(c->right!=0)
c->num+=c->right->num;
}
}
void add(int x)
{
add(arr,0,N-1,x);
}
int sum(vertex *c,int cl,int cr,int x,int left)
{
if(cl==cr)
return cl;
int cm=(cl+cr)>>1;
int sum_l,sum_r;
if(c->left==0)
{
sum_l=0;
if(cm-left-sum_l>=x)
return x+left;
}
else
sum_l=c->left->num;
if(c->right==0 && cm-left-sum_l<x)
return x+left+sum_l;
if(cm-left-sum_l<x)
return sum(c->right,cm+1,cr,x,left+sum_l);
else
return sum(c->left,cl,cm,x,left);
}
int get(int x)
{
return sum(arr,0,N-1,x,0);
}
};
sg_tree rooms;
main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
char t;
int r;
for(int i=0;i<m;i++)
{
cin>>t>>r;
if(t=='L')
cout<<rooms.get(r)<<"\n";
else
rooms.add(rooms.get(r));
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCB2ZXJ0ZXgKewogICAgdmVydGV4ICpsZWZ0LCpyaWdodDsKICAgIHNob3J0IG51bTsKfTsKCnN0cnVjdCBzZ190cmVlCnsKICAgIHN0YXRpYyBjb25zdCBpbnQgTVBPVz0zMTsKICAgIHN0YXRpYyBjb25zdCBpbnQgTj0xbGw8PE1QT1ctMTsKICAgIHZlcnRleCBhcnJbMTgwMDAwXTsKICAgIGludCBzejsKCiAgICBzZ190cmVlKCk6c3ooMSkKICAgIHsKICAgICAgICBhcnJbMF0ubGVmdD0wOwogICAgICAgIGFyclswXS5yaWdodD0wOwogICAgICAgIGFyclswXS5udW09MDsKICAgIH0KCiAgICB2b2lkIGFkZCh2ZXJ0ZXggKmMsaW50IGNsLGludCBjcixpbnQgeCkKICAgIHsKICAgICAgICBpZihjbD09Y3IpCiAgICAgICAgICAgIGMtPm51bT0xOwogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGludCBjbT0oY2wrY3IpPj4xOwogICAgICAgICAgICBpZih4PD1jbSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoYy0+bGVmdD09MCkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBjLT5sZWZ0PWFycitzejsKICAgICAgICAgICAgICAgICAgICBhcnJbc3pdLnJpZ2h0PTA7CiAgICAgICAgICAgICAgICAgICAgYXJyW3N6XS5sZWZ0PTA7CiAgICAgICAgICAgICAgICAgICAgc3orKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIGFkZChjLT5sZWZ0LGNsLGNtLHgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoYy0+cmlnaHQ9PTApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgYy0+cmlnaHQ9YXJyK3N6OwogICAgICAgICAgICAgICAgICAgIGFycltzel0ucmlnaHQ9MDsKICAgICAgICAgICAgICAgICAgICBhcnJbc3pdLmxlZnQ9MDsKICAgICAgICAgICAgICAgICAgICBzeisrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYWRkKGMtPnJpZ2h0LGNtKzEsY3IseCk7CgogICAgICAgICAgICB9CiAgICAgICAgICAgIGMtPm51bT0wOwogICAgICAgICAgICBpZihjLT5sZWZ0IT0wKQogICAgICAgICAgICAgICAgYy0+bnVtKz1jLT5sZWZ0LT5udW07CiAgICAgICAgICAgIGlmKGMtPnJpZ2h0IT0wKQogICAgICAgICAgICAgICAgYy0+bnVtKz1jLT5yaWdodC0+bnVtOwogICAgICAgIH0KICAgIH0KCiAgICB2b2lkIGFkZChpbnQgeCkKICAgIHsKICAgICAgICBhZGQoYXJyLDAsTi0xLHgpOwogICAgfQoKICAgIGludCBzdW0odmVydGV4ICpjLGludCBjbCxpbnQgY3IsaW50IHgsaW50IGxlZnQpCiAgICB7CiAgICAgICAgaWYoY2w9PWNyKQogICAgICAgICAgICByZXR1cm4gY2w7CiAgICAgICAgaW50IGNtPShjbCtjcik+PjE7CiAgICAgICAgaW50IHN1bV9sLHN1bV9yOwogICAgICAgIGlmKGMtPmxlZnQ9PTApCiAgICAgICAgewogICAgICAgICAgICBzdW1fbD0wOwogICAgICAgICAgICBpZihjbS1sZWZ0LXN1bV9sPj14KQogICAgICAgICAgICAgICAgcmV0dXJuIHgrbGVmdDsKCiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICBzdW1fbD1jLT5sZWZ0LT5udW07CiAgICAgICAgaWYoYy0+cmlnaHQ9PTAgJiYgY20tbGVmdC1zdW1fbDx4KQogICAgICAgICAgICByZXR1cm4geCtsZWZ0K3N1bV9sOwogICAgICAgIGlmKGNtLWxlZnQtc3VtX2w8eCkKICAgICAgICAgICAgcmV0dXJuIHN1bShjLT5yaWdodCxjbSsxLGNyLHgsbGVmdCtzdW1fbCk7CiAgICAgICAgZWxzZQogICAgICAgICAgICByZXR1cm4gc3VtKGMtPmxlZnQsY2wsY20seCxsZWZ0KTsKICAgIH0KCiAgICBpbnQgZ2V0KGludCB4KQogICAgewogICAgICAgcmV0dXJuIHN1bShhcnIsMCxOLTEseCwwKTsKICAgIH0KfTsKCnNnX3RyZWUgcm9vbXM7Cm1haW4oKQogewogICAgaW9zOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBjaW4udGllKDApOwogICAgaW50IG4sbTsKICAgIGNpbj4+bj4+bTsKICAgIGNoYXIgdDsKICAgIGludCByOwogICAgZm9yKGludCBpPTA7aTxtO2krKykKICAgIHsKICAgICAgICBjaW4+PnQ+PnI7CiAgICAgICAgaWYodD09J0wnKQogICAgICAgICAgICBjb3V0PDxyb29tcy5nZXQocik8PCJcbiI7CiAgICAgICAgZWxzZQogICAgICAgICAgICByb29tcy5hZGQocm9vbXMuZ2V0KHIpKTsKICAgIH0KfQ==