#include<stdio.h>
#include<stdlib.h>
struct node{
    int id;
    struct node*next;
};
int main(){
    struct nod*f=NULL,*r=NULL,*t;
    int n,id,at;
    scanf("%d",&n);
    if(n<=0){ printf("Invalid input");
    return 0; }
    while(n--){
        scanf("%d%d",&id,&at);
        if(id<=0 || at<0){ printf("Invalid input");
        return 0; }
        t=(struct node*)malloc(sizeof(struct node));
        t->id=id; t->next=NULL;
        if(!f) f=r=t;
        else { r->next=t; r=t; }
    }
    while(f){
        printf("%d\n",f->id);
        f=f->next;
    }
}