import java.util.*;
public class Main {
static int first = 0;
static int last = 0;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
int[] queue = new int[n + 1];
int opts = input.nextInt();
String line = input.nextLine();
for (int i = 0; i < opts; i++) {
line = input.nextLine();
if ("pop".equals(line)) {
pop(queue);
} else if ("front".equals(line)) {
front(queue);
} else {
push(queue, Integer.parseInt(line.substring(5)));
}
}
}
public static void push(int[] queue, int target){
if(!isFull(queue)){
last = (last+1)%queue.length;
queue[last] = target;
}else{
System.out.println("full");
}
}
public static void pop(int[] queue){
if(!isEmpty()){
first = (first+1)%queue.length;
System.out.println(queue[first]);
}else{
System.out.println("empty");
}
}
public static void front(int[] queue){
if(!isEmpty()){
System.out.println(queue[(first+1)%queue.length]);
}else{
System.out.println("empty");
}
}
public static boolean isEmpty(){
return first == last;
}
public static boolean isFull(int[] queue){
return (last+1)%(queue.length) == first;
}
}