#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));
    }
}