#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 p){
    struct Node*newNode=(struct Node*)malloc(sizeof(struct Node));
    newNode ->id=id;
    newNode ->p=p;
    newNode->next=NULL;
    if(head==NULL||head->p<p){
        newNode->next=head;
        head=newNode;
    }else{
        struct Node*temp=head;
        while(temp->next!=NULL && temp->next->p>=p){
            temp=temp->next;
        }
        nextNode->next=temp->next;
        temp->next=newNode;
        
    }
}
void delete(){
    if(head==NULL){
        return;
    }
    struct Node*temp=head;
    printf("%d",temp->id);
    head=head->next;
    free(temp);
    
}
int main(){
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        char op[0];
        scanf("%s",op);
        if(strcmp(op,"INSERT")==0){
            int id,p;
            scanf("%d%d",&id,&p);
            insert(id,p);
        }else if(strcmp(op,"delete")==0){
            delete();
        }
    }
    return 0;
}