#include <bits/stdc++.h>
using namespace std;
struct vertex
{
int left,right;
int num;
};
struct sg_tree
{
static const int MPOW=31;
static const int N=1ll<<MPOW-1;
vertex arr[200000];
int sz;
sg_tree():sz(1)
{
arr[0].left=-1;
arr[0].right=-1;
arr[0].num=0;
}
void add(int c,int cl,int cr,int x)
{
if(cl==cr)
arr[c].num=1;
else
{
int cm=(cl+cr)>>1;
if(x<=cm)
{
if(arr[c].left==-1)
{
arr[c].left=sz;
arr[sz].right=-1;
arr[sz].left=-1;
sz++;
}
add(arr[c].left,cl,cm,x);
}
else
{
if(arr[c].right==-1)
{
arr[c].right=sz;
arr[sz].right=-1;
arr[sz].left=-1;
sz++;
}
add(arr[c].right,cm+1,cr,x);
}
arr[c].num=0;
if(arr[c].left+1)
arr[c].num+=arr[arr[c].left].num;
if(arr[c].right+1)
arr[c].num+=arr[arr[c].right].num;
}
}
void add(int x)
{
add(0,0,N-1,x);
}
int sum(int c,int cl,int cr,int l,int r)
{
if(c==-1)
return 0;
if(l>r)
return 0;
if(l==cl && r==cr)
return arr[c].num;
int cm=(cl+cr)>>1;
return sum(arr[c].left,cl,cm,l,min(r,cm))+sum(arr[c].right,cm+1,cr,max(l,cm+1),r);
}
int get(int x)
{
return sum(0,0,N-1,0,x);
}
};
int get_room(sg_tree &sg,int k)
{
int l=0,r=1e9+1;
while(l<r)
{
int m=l+((r-l)>>1);
if(m-sg.get(m)<k)
l=m+1;
else
r=m;
}
return l;
}
main()
{
ios::sync_with_stdio(0);
int n,m;
cin>>n>>m;
char t;
int r;
sg_tree rooms;
for(int i=0;i<m;i++)
{
cin>>t>>r;
if(t=='L')
cout<<get_room(rooms,r)<<endl;
else
rooms.add(get_room(rooms,r));
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IHZlcnRleAp7CiAgICBpbnQgbGVmdCxyaWdodDsKICAgIGludCBudW07Cn07CgpzdHJ1Y3Qgc2dfdHJlZQp7CiAgICBzdGF0aWMgY29uc3QgaW50IE1QT1c9MzE7CiAgICBzdGF0aWMgY29uc3QgaW50IE49MWxsPDxNUE9XLTE7CiAgICB2ZXJ0ZXggYXJyWzIwMDAwMF07CiAgICBpbnQgc3o7CgogICAgc2dfdHJlZSgpOnN6KDEpCiAgICB7CiAgICAgICAgYXJyWzBdLmxlZnQ9LTE7CiAgICAgICAgYXJyWzBdLnJpZ2h0PS0xOwogICAgICAgIGFyclswXS5udW09MDsKICAgIH0KCiAgICB2b2lkIGFkZChpbnQgYyxpbnQgY2wsaW50IGNyLGludCB4KQogICAgewogICAgICAgIGlmKGNsPT1jcikKICAgICAgICAgICAgYXJyW2NdLm51bT0xOwogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIGludCBjbT0oY2wrY3IpPj4xOwogICAgICAgICAgICBpZih4PD1jbSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgaWYoYXJyW2NdLmxlZnQ9PS0xKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGFycltjXS5sZWZ0PXN6OwogICAgICAgICAgICAgICAgICAgIGFycltzel0ucmlnaHQ9LTE7CiAgICAgICAgICAgICAgICAgICAgYXJyW3N6XS5sZWZ0PS0xOwogICAgICAgICAgICAgICAgICAgIHN6Kys7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBhZGQoYXJyW2NdLmxlZnQsY2wsY20seCk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZihhcnJbY10ucmlnaHQ9PS0xKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGFycltjXS5yaWdodD1zejsKICAgICAgICAgICAgICAgICAgICBhcnJbc3pdLnJpZ2h0PS0xOwogICAgICAgICAgICAgICAgICAgIGFycltzel0ubGVmdD0tMTsKICAgICAgICAgICAgICAgICAgICBzeisrOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgYWRkKGFycltjXS5yaWdodCxjbSsxLGNyLHgpOwoKICAgICAgICAgICAgfQogICAgICAgICAgICBhcnJbY10ubnVtPTA7CiAgICAgICAgICAgIGlmKGFycltjXS5sZWZ0KzEpCiAgICAgICAgICAgICAgICBhcnJbY10ubnVtKz1hcnJbYXJyW2NdLmxlZnRdLm51bTsKICAgICAgICAgICAgaWYoYXJyW2NdLnJpZ2h0KzEpCiAgICAgICAgICAgICAgICBhcnJbY10ubnVtKz1hcnJbYXJyW2NdLnJpZ2h0XS5udW07CiAgICAgICAgfQogICAgfQoKICAgIHZvaWQgYWRkKGludCB4KQogICAgewogICAgICAgIGFkZCgwLDAsTi0xLHgpOwogICAgfQoKICAgIGludCBzdW0oaW50IGMsaW50IGNsLGludCBjcixpbnQgbCxpbnQgcikKICAgIHsKICAgICAgICBpZihjPT0tMSkKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgaWYobD5yKQogICAgICAgICAgICByZXR1cm4gMDsKICAgICAgICBpZihsPT1jbCAmJiByPT1jcikKICAgICAgICAgICAgcmV0dXJuIGFycltjXS5udW07CiAgICAgICAgaW50IGNtPShjbCtjcik+PjE7CiAgICAgICAgcmV0dXJuIHN1bShhcnJbY10ubGVmdCxjbCxjbSxsLG1pbihyLGNtKSkrc3VtKGFycltjXS5yaWdodCxjbSsxLGNyLG1heChsLGNtKzEpLHIpOwogICAgfQoKICAgIGludCBnZXQoaW50IHgpCiAgICB7CiAgICAgICByZXR1cm4gc3VtKDAsMCxOLTEsMCx4KTsKICAgIH0KfTsKCmludCBnZXRfcm9vbShzZ190cmVlICZzZyxpbnQgaykKewogICAgaW50IGw9MCxyPTFlOSsxOwogICAgd2hpbGUobDxyKQogICAgewogICAgICAgIGludCBtPWwrKChyLWwpPj4xKTsKICAgICAgICBpZihtLXNnLmdldChtKTxrKQogICAgICAgICAgICBsPW0rMTsKICAgICAgICBlbHNlCiAgICAgICAgICAgIHI9bTsKICAgIH0KICAgIHJldHVybiBsOwp9CgptYWluKCkKIHsKICAgIGlvczo6c3luY193aXRoX3N0ZGlvKDApOwogICAgaW50IG4sbTsKICAgIGNpbj4+bj4+bTsKICAgIGNoYXIgdDsKICAgIGludCByOwogICAgc2dfdHJlZSByb29tczsKICAgIGZvcihpbnQgaT0wO2k8bTtpKyspCiAgICB7CiAgICAgICAgY2luPj50Pj5yOwogICAgICAgIGlmKHQ9PSdMJykKICAgICAgICAgICAgY291dDw8Z2V0X3Jvb20ocm9vbXMscik8PGVuZGw7CiAgICAgICAgZWxzZQogICAgICAgICAgICByb29tcy5hZGQoZ2V0X3Jvb20ocm9vbXMscikpOwogICAgfQp9Cg==