#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
    int id;
    int priority;
    struct Node*next;
};
struct Node*head=NULL;

void insert(int id,int priority){
    struct Node*newNode=(struct Node*)malloc(sizeof(struct node));
    newNode->id=id;
    newNode->priority=priority;
    newNode->next=NULL;
    
    if(head==NULL|| head->priority<priority){
        newNode->next=head;
        head=newNode;
    }else{
        struct Node*temp=head;
    }
    newNode->next=temp->next;
    temp->next=newNode;
    }
}
void delete(){
    if(head==NULL){
        printf("Queue is empty");
        return;
    }
    struct Node*temp=head;
    printf("%d\n",temp->id);
    head=head->next;
    free(temp);
}
int main(){
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        char op[10];
        scanf("%s",op);
        
        if(strcmp(op,"INSERT")==0){
            int id,p;
            scanf(strcmp(op,"DELETE")==0){
                delete();
            }
        }
        return 0;
    }