#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <int> vi;
typedef pair <int, int> ii;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define PB push_back
#define MP make_pair
#define OO (1000000000)
#define EPS (1e-9)
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
freopen("in.in", "rt", stdin);
if(outToFile)
freopen("out.out", "wt", stdout);
#endif
}
//
typedef unsigned int uint;
#define nmMax 1000000+9
map < uint, queue <int> > q;
int n, m;
uint x;
char cmd;
int rnk;
//
int main()
{
read_file();
rnk = 1;
scanf("%d %d\n", &n, &m);
while(n--)
{
scanf("%u ", &x);
q[x].push(rnk++);
}
while(m--)
{
scanf("%c %u\n", &cmd, &x);
if(cmd == 'I')
{
printf("%d\n", rnk);
q[x].push(rnk++);
}
else if(cmd == 'S')
{
if(q[x].empty())
printf("NONE\n");
else
printf("%d\n", q[x].front());
}
else
{
if(q[x].empty())
printf("NONE\n");
else
printf("%d\n", q[x].front()), q[x].pop();
}
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHZlY3RvciA8aW50PiB2aTsKdHlwZWRlZiBwYWlyIDxpbnQsIGludD4gaWk7CnR5cGVkZWYgdmVjdG9yIDx2aT4gdnZpOwp0eXBlZGVmIHZlY3RvciA8aWk+IHZpaTsKdHlwZWRlZiB2ZWN0b3IgPHZpaT4gdnZpaTsKI2RlZmluZSBQQiBwdXNoX2JhY2sKI2RlZmluZSBNUCBtYWtlX3BhaXIKI2RlZmluZSBPTyAoMTAwMDAwMDAwMCkKI2RlZmluZSBFUFMgKDFlLTkpCiNkZWZpbmUgYWxsKHYpICgodikuYmVnaW4oKSksKCh2KS5lbmQoKSkKI2RlZmluZSBERUJVRy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ogICAgICAgIHsKICAgICAgICAgICAgaWYocVt4XS5lbXB0eSgpKQogICAgICAgICAgICAgICAgcHJpbnRmKCJOT05FXG4iKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgcHJpbnRmKCIlZFxuIiwgcVt4XS5mcm9udCgpKSwgcVt4XS5wb3AoKTsKICAgICAgICB9CiAgICB9Cn0K