#include<iostream>
#include<stack>
using namespace std;
stack<int> stk1,stk2;
int n,m,x;
char c;
int main(){
cin >> n >> m;
getchar();
int t1 = min(n,m);
while(1){
cin >> c;
if(c == 'T') break;
if(c == 'A'){
cin >> x;
if(stk1.size() == t1 && stk2.size() > 0){
cout<<"ERROR:Full\n";
}
else if(stk1.size() == t1){
while(stk1.size()){
int t = stk1.top();
stk2.push(t);
stk1.pop();
}
stk1.push(x);
}
else stk1.push(x);
}else if(c == 'D'){
if(stk2.size() > 0){
cout<<stk2.top()<<endl;
stk2.pop();
}else if(stk2.size() == 0 && stk1.size() > 0){
while(stk1.size()){
int t = stk1.top();
stk2.push(t);
stk1.pop();
}
cout<<stk2.top()<<endl;
stk2.pop();
}else{
cout<<"ERROR:Empty\n";
}
}
}
return 0;
}