#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <iostream>
#define rep(i, l, r) for(int i = l; i <= r; i++)
#define down(i, l, r) for(int i = l; i >= r; i--)
#define MS 123456
#define MAX 1037471823
#define Q 1
using namespace std;
int n, m, low, a, l[MS], r[MS], h[MS], s[MS], ans, now;
long long k[MS];
char q[5];
void Splay(int x)
{
if (!x) return; int o = h[x];
while (o)
{
if (l[o] == x) { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o], h[r[x]] = o, l[o] = r[x], h[o] = x, r[x] = o, s[o] = s[l[o]] + s[r[o]] + 1, s[x] = s[l[x]] + s[r[x]] + 1; }
else { l[h[o]] == o ? l[h[o]] = x : r[h[o]] = x; h[x] = h[o], h[l[x]] = o, r[o] = l[x], h[o] = x, l[x] = o, s[o] = s[l[o]] + s[r[o]] + 1, s[x] = s[l[x]] + s[r[x]] + 1; }
o = h[x];
}
}
int Pre(int x)
{
int o; if (r[x]) for (o = r[x]; l[o]; o = l[o]); else for (o = h[x]; o && l[o] != x; x = o, o = h[x]); return o;
}
void Insert(int x)
{
if (x < low - m) return;
if (l[0] == 0) { now++, s[now] = 1, h[now] = l[now] = r[now] = 0, k[now] = x, l[0] = now; return; }
int o; for (o = l[0]; x < k[o]?l[o]:r[o];) s[o]++, o = x < k[o]?l[o]:r[o]; s[o]++;
now++; if (x < k[o]) l[o] = now; else r[o] = now; s[now] = 1, h[now] = o, l[now] = r[now] = 0, k[now] = x; Splay(now);
}
void Check(double x)
{
if (l[0] == 0) return;
int o; for (o = l[0]; x < k[o]?l[o]:r[o];) s[o]++, o = x < k[o]?l[o]:r[o]; s[o]++;
now++; if (x < k[o]) l[o] = now; else r[o] = now; s[now] = 1, h[now] = o, l[now] = r[now] = 0;
if (Pre(now)) { Splay(Pre(now)); ans += s[l[l[0]]]-1, s[l[0]] -= s[l[l[0]]]; l[l[0]] = 0; } else ans += s[l[0]]-1, l[0] = 0; now--;
}
int FindRW(int x)
{
if (x >= s[l[0]]) return -1-m; int o = l[0];
while (x != s[r[o]]) if (x < s[r[o]]) o = r[o]; else x -= s[r[o]] + 1, o = l[o];
return k[o];
}
int main()
{
scanf("%d%d", &n, &low); ans = m = 0;
rep(i, 1, n)
{
scanf("%s%d", q, &a);
if (q[0] == 'I') Insert(a-m);
else if (q[0] == 'A') m += a;
else if (q[0] == 'S') { m -= a; Check(low-m-0.5); }
else if (q[0] == 'F') printf("%d\n", FindRW(a-1)+m);
}
printf("%d\n", ans);
return 0;
}
I2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNpbmNsdWRlIDxjc3RkaW8+CiNpbmNsdWRlIDxmc3RyZWFtPgojaW5jbHVkZSA8aW9zdHJlYW0+CgojZGVmaW5lIHJlcChpLCBsLCByKSBmb3IoaW50IGkgPSBsOyBpIDw9IHI7IGkrKykKI2RlZmluZSBkb3duKGksIGwsIHIpIGZvcihpbnQgaSA9IGw7IGkgPj0gcjsgaS0tKQojZGVmaW5lIE1TIDEyMzQ1NgojZGVmaW5lIE1BWCAxMDM3NDcxODIzCiNkZWZpbmUgUSAxCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIG0sIGxvdywgYSwgbFtNU10sIHJbTVNdLCBoW01TXSwgc1tNU10sIGFucywgbm93Owpsb25nIGxvbmcga1tNU107CmNoYXIgcVs1XTsKCnZvaWQgU3BsYXkoaW50IHgpCnsKCWlmICgheCkgcmV0dXJuOyBpbnQgbyA9IGhbeF07Cgl3aGlsZSAobykKCXsKCQlpZiAobFtvXSA9PSB4KSB7IGxbaFtvXV0gPT0gbyA/IGxbaFtvXV0gPSB4IDogcltoW29dXSA9IHg7IGhbeF0gPSBoW29dLCBoW3JbeF1dID0gbywgbFtvXSA9IHJbeF0sIGhbb10gPSB4LCByW3hdID0gbywgc1tvXSA9IHNbbFtvXV0gKyBzW3Jbb11dICsgMSwgc1t4XSA9IHNbbFt4XV0gKyBzW3JbeF1dICsgMTsgfSAKCQllbHNlIHsgbFtoW29dXSA9PSBvID8gbFtoW29dXSA9IHggOiByW2hbb11dID0geDsgaFt4XSA9IGhbb10sIGhbbFt4XV0gPSBvLCByW29dID0gbFt4XSwgaFtvXSA9IHgsIGxbeF0gPSBvLCBzW29dID0gc1tsW29dXSArIHNbcltvXV0gKyAxLCBzW3hdID0gc1tsW3hdXSArIHNbclt4XV0gKyAxOyB9IAoJCW8gPSBoW3hdOwoJfQp9CgppbnQgUHJlKGludCB4KQp7CglpbnQgbzsgaWYgKHJbeF0pIGZvciAobyA9IHJbeF07IGxbb107IG8gPSBsW29dKTsgZWxzZSBmb3IgKG8gPSBoW3hdOyBvICYmIGxbb10gIT0geDsgeCA9IG8sIG8gPSBoW3hdKTsgcmV0dXJuIG87Cn0KCnZvaWQgSW5zZXJ0KGludCB4KQp7CglpZiAoeCA8IGxvdyAtIG0pIHJldHVybjsKCWlmIChsWzBdID09IDApIHsgbm93KyssIHNbbm93XSA9IDEsIGhbbm93XSA9IGxbbm93XSA9IHJbbm93XSA9IDAsIGtbbm93XSA9IHgsIGxbMF0gPSBub3c7IHJldHVybjsgfQoJaW50IG87IGZvciAobyA9IGxbMF07IHggPCBrW29dP2xbb106cltvXTspIHNbb10rKywgbyA9IHggPCBrW29dP2xbb106cltvXTsgc1tvXSsrOwoJbm93Kys7IGlmICh4IDwga1tvXSkgbFtvXSA9IG5vdzsgZWxzZSByW29dID0gbm93OyBzW25vd10gPSAxLCBoW25vd10gPSBvLCBsW25vd10gPSByW25vd10gPSAwLCBrW25vd10gPSB4OyBTcGxheShub3cpOwp9Cgp2b2lkIENoZWNrKGRvdWJsZSB4KQp7CglpZiAobFswXSA9PSAwKSByZXR1cm47CglpbnQgbzsgZm9yIChvID0gbFswXTsgeCA8IGtbb10/bFtvXTpyW29dOykgc1tvXSsrLCBvID0geCA8IGtbb10/bFtvX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