#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<stack>
#include<queue>
using namespace std;
string a[2000021],b[2000021];
int n,m;
int main()
{
while(cin >> n >> m)
{
int flag = 0;
string str,num;
int h = 0,k1 = 0,k2 = 0;
for(int i=0; i<m; i++)
{
cin >> str;
if(str == "Add")
{
cin >> num;
if(h<n)
{
a[++h] = num;
}
else
{
b[++k2] = num;
}
}
else if(str == "Del")
{
if(h<=0)
{
flag = 1;
}
else if(k2 > k1)
{
a[h] = b[++k1];
}
else if(k2<=k1)
{
h--;
}
}
else if(str == "Out")
{
if(k2 <= k1)
{
flag = 1;
}
else
{
k1++;
}
}
}
if(h>0 && flag == 0)
{
while(h>0)
{
cout << a[h] << endl;
h--;
}
}
else if(flag == 1)
{
cout << "Error" << endl;
}
}
return 0;
}
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<stack>
#include<queue>
using namespace std;
int n,m;
int main()
{
while(cin >> n >> m)
{
stack<string>a;
queue<string>b;
int flag = 0;
string str,num;
for(int i=0; i<m; i++)
{
cin >> str;
if(str == "Add")
{
cin >> num;
if(a.size() == n)
{
b.push(num);
}
else
{
a.push(num);
}
}
else if(str == "Del")
{
if(a.empty())
{
flag = 1;
}
else
{
a.pop();
if(!b.empty())
{
a.push(b.front());
b.pop();
}
}
}
else if(str == "Out")
{
if(b.empty())
{
flag = 1;
}
else
{
b.pop();
}
}
}
if(flag == 1)
{
cout << "Error" << endl;
}
else
{
while(!a.empty())
{
cout << a.top() << endl;
a.pop();
}
}
}
return 0;
}