#include<bits/stdc++.h>
using namespace std;
#define inf 0x7fffffff
const int MX=3*100000+10;
inline int read()
{
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
int n,m;
int tree[MX][2],value[MX],father[MX],size[MX],cnt[MX];
int root;
int tot=0;
int cha=0;
int all_num=0;
inline int creat(int v)
{
value[++tot]=v;
size[tot]=cnt[tot]=1;
return tot;
}
inline int get_lr(int x)
{
return tree[father[x]][1]==x;
}
inline void pushup(int x)
{
if(x)
{
size[x]=size[tree[x][0]]+size[tree[x][1]]+cnt[x];
}
}
inline void rotate(int x)
{
int fa=father[x],gfa=father[father[x]];
int p=get_lr(x);
tree[fa][p]=tree[x][p^1],father[tree[fa][p]]=fa;
father[fa]=x;
tree[x][p^1]=fa;
father[x]=gfa;
if(gfa)
{
tree[gfa][tree[gfa][1]==fa]=x;
}
pushup(fa),pushup(x);
}
inline void splay(int x)
{
for(int fa;fa=father[x];rotate(x))
{
if(father[fa])
{
rotate(get_lr(x)==get_lr(fa)?fa:x);
}
}
root=x;
}
inline void insert(int x)
{
if(!root)
{
value[root=++tot]=x;
size[tot]=cnt[tot]=1;
return ;
}
int now=root,fa=0;
while(1)
{
if(value[now]==x)
{
cnt[now]++;
pushup(now),pushup(fa);
splay(now);
return ;
}
fa=now,now=tree[now][x>value[now]];
if(!now)
{
father[++tot]=fa,value[tot]=x;
size[tot]=cnt[tot]=1;
tree[fa][value[fa]<x]=tot;
pushup(fa);
splay(tot);
return ;
}
}
}
inline int getrank(int x)
{
if(!root) return 0;
int now=root,ans=0;
while(1)
{
if(x<value[now])
{
now=tree[now][0];
}
else
{
ans+=size[tree[now][0]];
if(x==value[now])
{
splay(now);
return ans+1;
}
ans+=cnt[now],now=tree[now][1];
}
}
}
inline int getnum(int x)
{
if(!root) return 0;
int now=root;
while(1)
{
if(x<=size[tree[now][0]]) now=tree[now][0];
else
{
int p=size[tree[now][0]]+cnt[now];
if(x<=p) return value[now];
x-=p;
now=tree[now][1];
}
}
}
inline int getpre()
{
int now=tree[root][0];
while(tree[now][1])
{
now=tree[now][1];
}
return now;
}
inline int getsuf()
{
int now=tree[root][1];
while(tree[now][0])
{
now=tree[now][0];
}
return now;
}
inline void del()
{
int now=root,now2=0;
int rm=m-cha;
while(now)
{
if(value[now]<rm)
{
tree[now][0]=0;
now=tree[now][1];
if(now) father[now]=now2;
if(now2) tree[now2][0]=now;
pushup(now),pushup(now2);
}
else
{
now2=now;
now=tree[now][0];
}
}
if(now2) splay(now2);
pushup(root);
}
int main()
{
n=read(),m=read();
for(int i=1;i<=n;i++)
{
char ina[2];
int inb;
scanf("%s",&ina);
if(ina[0]=='I')
{
inb=read();
if(inb>=m)
{
all_num++;
insert(inb-cha);
}
}
else if(ina[0]=='A')
{
inb=read();
cha+=inb;
}
else if(ina[0]=='S')
{
inb=read();
cha-=inb;
del();
}
else if(ina[0]=='F')
{
inb=read();
if(size[root]<inb) printf("-1\n");
else
{
printf("%d\n", getnum(size[root]-inb+1)+cha);
}
}
}
printf("%d\n", all_num-size[root]);
return 0;
}