#include<iostream>
#include<string>
#include<deque>
using namespace std;
deque<int>dq;
int main()
{
int N, M;
cin >> N >> M;
for (int i = 0; i < M; i++)
{
string str;
int id;
cin >> str;
if (str == "pushLeft" || str == "pushRight")
{
cin >> id;
if (dq.size() >= N)
cout << "The queue is full" << endl;
else
{
if (str == "pushLeft")
{
dq.push_front(id);
cout << "Pushed in left: " << id << endl;
}
if (str == "pushRight")
{
dq.push_back(id);
cout << "Pushed in right: " << id << endl;
}
}
}
if (str == "popLeft" || str == "popRight")
{
if (dq.size() == 0)
cout << "The queue is empty" << endl;
else
{
if (str == "popLeft")
{
int tmp = dq.front();
dq.pop_front();
cout << "Popped from left: " << tmp << endl;
}
if (str == "popRight")
{
int tmp = dq.back();
dq.pop_back();
cout << "Popped from right: " << tmp << endl;
}
}
}
}
return 0;
}