#include<stdio.h>
#include<stdlib.h>
typedef struct node{
    int id;
    int ar;
    struct node *next;
}Node;
Node *front=NULL,*rear=NULL;
void enqueue(int v,int t){
    Node *newnode=(Node*)malloc(sizeof(Node));
    newnode->id=v;
    newnode->ar=t;
    newnode->next=NULL;
    if(front==NULL){
        front=rear=newnode;
    }
    else{
        rear->next=newnode;
        rear=newnode;
    }
}
void sort(){
    Node *i,*j;
    for(int i=front;i!=NULL;i=i->next){
        for(int j=i->next;j!=NULL;j=j->next){
            if(i->ar > j->ar){
                int tid=i->id,tar=i->ar;
                i->id=j->id;
                i->ar=j->ar;
                j->id=tid;
                j->ar=tar;
            }
        }
    }
}
void dequeue(){
    while(front!=NULL){
        Node *temp=front;
        printf("%d\n",front->id);
        front=front->next;
        free(temp);
    }
}
int main(){
    int n,x,y;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%d %d",&x,&y);
        if(x<=0 || y<=0 ){
            printf("Invalid input");
            return 0;
        }
        enqueue(x,y);
    }
    sort();
    dequeue();
    return 0;
}