#include<stdio.h>
#include<stdlib.h>
struct Node{
    int id;
    struct Node *next;
};
int main(){
    int n,id,arr;
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid Input");
        return 0;
    }
    struct Node *front=NULL,*rear=NULL,*temp;
    for(int i=0;i<n;i++){
        scanf("%d %d",&id,&arr);
        if(id<=0||arr<0){
            printf("Invalid input\n");
            return 0;
        }
        temp=malloc(sizeof(struct Node));
        temp->id=id;
        temp->next=NULL;
        if(!rear)front=rear=temp;
        else{rear->next=temp;rear=temp;}
    }
    while(front){
        printf("%d\n",front-<id);
        temp=front;
        front=front->next;
        free(temp);
    }
    return 0;
    
}