#include<bits/stdc++.h>
#include<stack>
#include<queue>
using namespace std;
int n,m,y,w,num;
char x;
int main()
{
stack<int> st1,st2,sj1,sj2;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>x;
if(x=='A'){
cin>>y;
st1.push(y%m);
}
else{
cin>>w;
num=0;
for(int j=1;j<=w;j++){
st2.push(st1.top());
if(num<=st1.top()) num=st1.top();
st1.pop();
}
for(int j=1;j<=w;j++){
st1.push(st2.top());
st2.pop();
}
sj1.push(num);
}
}
while(sj1.empty()==0)
{
sj2.push(sj1.top());
sj1.pop();
}
while(sj2.empty()==0)
{
cout<<sj2.top()<<endl;
sj2.pop();
}
return 0;