#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define N 100010
using namespace std;
typedef long long LL;
typedef long double LD;
int n,Min;
struct Splay
{
int lc[3*N],rc[3*N],tp[3*N],s[3*N],fa[3*N],key[3*N];
int root,len,cnt,inf;
void init(){root=len=cnt=0;inf=2e9;}
void lt(int x)
{
int y=fa[x];tp[x]=tp[y];fa[x]=fa[y];tp[y]=1;fa[y]=x;
s[x]=s[y];s[y]=s[rc[y]]+s[rc[x]]+1;
if (rc[x]!=0) {fa[rc[x]]=y;tp[rc[x]]=0;}
lc[y]=rc[x];rc[x]=y;
if (fa[x]==0) root=x;
}
void rt(int x)
{
int y=fa[x];tp[x]=tp[y];fa[x]=fa[y];tp[y]=0;fa[y]=x;
s[x]=s[y];s[y]=s[lc[y]]+s[lc[x]]+1;
if (lc[x]!=0) {fa[lc[x]]=y;tp[lc[x]]=1;}
rc[y]=lc[x];lc[x]=y;
if (fa[x]==0) root=x;
}
void splay(int x)
{
int t=x;
while (t!=root)
{
if (tp[t]==0) lt(t);else rt(t);
}
}
void ins(int x,int Key)
{
if (root==0) {cnt++;key[++len]=Key;fa[len]=0;root=len;s[root]=1;return;}
s[x]++;
if (Key<key[x])
{
if (lc[x]==0)
{
lc[x]=++len;fa[lc[x]]=x;s[lc[x]]=1;tp[lc[x]]=0;key[lc[x]]=Key;
splay(lc[x]);cnt++;
}
else ins(lc[x],Key);
}else
{
if (rc[x]==0)
{
rc[x]=++len;fa[rc[x]]=x;s[rc[x]]=1;tp[rc[x]]=1;key[rc[x]]=Key;
splay(rc[x]);cnt++;
}
else ins(rc[x],Key);
}
}
int select(int x,int ks)
{
if (s[x]==1) return x;
int ls=s[lc[x]]+1;
if (ks<ls) return select(lc[x],ks);
if (ks==ls) return x;
if (ks>ls) return select(rc[x],ks-ls);
}
int find(int x,int Key)
{
if (x==0) return inf;
if (Key==key[x]) {splay(x);return x;}
if (Key<key[x])
{
if (lc[x]==0) return inf;
return find(lc[x],Key);
}else
{
if (rc[x]==0) return inf;
return find(rc[x],Key);
}
}
int getmin(int x)
{
if (lc[x]==0) {splay(x);return x;}
return getmin(lc[x]);
}
int getmax(int x)
{
if (rc[x]==0) {splay(x);return x;}
return getmax(rc[x]);
}
int del(int Key)
{
int x=find(root,Key);
if (x==inf) return 0;cnt--;
if (cnt==0) {root=0;return 1;}
splay(x);
if (lc[x]==0) root=rc[x];
else
{
int maxpos=getmax(lc[x]);
splay(x);
root=lc[x];int Rroot=rc[x];
splay(maxpos);s[root]+=s[Rroot];
fa[Rroot]=root;rc[root]=Rroot;
}
fa[root]=0;
}
}tree;
int main()
{
ios::sync_with_stdio(false);
scanf("%d%d",&n,&Min);
int tmp=0,tot=0,i,t;char s[3];
FOR(i,1,n)
{
scanf("%s%d",s,&t);
if (s[0]=='A') tmp+=t;
if (s[0]=='S')
{
tmp-=t;
while (tree.cnt)
{
int pos=tree.getmin(tree.root);
if (tree.key[pos]+tmp<Min)
{
tree.del(tree.key[pos]);
tot++;
}else break;
}
}
if (s[0]=='F')
{
t=tree.cnt-t+1;
if (t<=0) printf("-1\n");
else printf("%d\n",tree.key[tree.select(tree.root,t)]+tmp);
}
if (s[0]=='I')
{
if (t<Min) continue;
tree.ins(tree.root,t-tmp);
}
}
printf("%d\n",tot);
return 0;
}