#include "bits/stdc++.h"
using namespace std;
const int maxn=1e5+5;
int rk[maxn],fw[maxn],Min,tag,n,cnt,ans;
priority_queue<int,vector<int>,greater<int> > pq;
inline int find(const int x) {return lower_bound(rk+1,rk+cnt+1,x)-rk;}
struct node {
int op,x;
}q[3*maxn];
inline void ins(int x,int d) {
for(int i=x;i<=cnt;i+=i&-i)
fw[i]+=d;
}
inline int sum(int x) {
int res=0;
for(int i=x;i;i-=i&-i)
res+=fw[i];
return res;
}
inline int kth(int x) {
int l=1,r=cnt,res;
if(pq.size()<x) return -1;
x=pq.size()-x+1;
while(l<=r) {
int mid=l+r>>1;
if(sum(mid)>=x) {
res=mid;
r=mid-1;
} else l=mid+1;
}
return rk[res]+tag;
}
signed main() {
ios::sync_with_stdio(0);
cin>>n>>Min;
for(int i=1;i<=n;++i) {
char ch; int x;
cin>>ch>>x;
if(ch=='I') {
if(x<Min) {
--i; --n;
continue;
}
rk[++cnt]=x-tag;
q[i]=node{0,x-tag};
} if(ch=='A') {
tag+=x;
q[i]=node{1,x};
} if(ch=='S') {
tag-=x;
q[i]=node{1,-x};
} if(ch=='F') {
q[i]=node{2,x};
}
}
sort(rk,rk+cnt+1);
cnt=unique(rk+1,rk+cnt+1)-rk;
tag=0;
for(int i=1;i<=n;++i) {
if(q[i].op==0) {
ins(find(q[i].x),1);
pq.push(q[i].x);
} if(q[i].op==1) {
tag+=q[i].x;
while(!pq.empty()&&pq.top()+tag<Min) {
++ans;
ins(find(pq.top()),-1);
pq.pop();
}
} if(q[i].op==2) {
cout<<kth(q[i].x)<<'\n';
}
}
cout<<ans;
return 0;
}