#include <stdio.h>
#include <stdlib.h>

typedef struct __LinkedList_ts {
    int value;
    struct __LinkedList_ts* next;
} LinkedList_ts;

LinkedList_ts* LinkedList_new(int value)
{
    LinkedList_ts* result = NULL;

    result = (LinkedList_ts*)malloc(sizeof(LinkedList_ts));
    result->value = value;
    result->next = NULL;

    return result;
}

LinkedList_ts* LinkedList_add(LinkedList_ts* head, int value, int pos)
{
    LinkedList_ts* result = NULL;
    LinkedList_ts* curr = NULL;
    LinkedList_ts* prev = NULL;
    LinkedList_ts* next = NULL;
    LinkedList_ts* node = NULL;

    if (head == NULL) {
        node = LinkedList_new(value);
        head = node;
    } else {
        for (curr=head; curr!=NULL; prev=curr,curr=curr->next) {
            next = curr->next;
            if (curr->value == pos) {
                node = LinkedList_new(value);
                node->next = next;
                curr->next = node;
            } else {}
        }
    }
    result = head;

    return result;
}

LinkedList_ts* LinkedList_delete(LinkedList_ts* head, int value)
{
    LinkedList_ts* result = NULL;
    LinkedList_ts* curr = NULL;
    LinkedList_ts* prev = NULL;
    LinkedList_ts* next = NULL;

    if (head != NULL) {
        for (curr=head; curr!=NULL; prev=curr,curr=curr->next) {
            if (value == curr->value) {
                if (curr == head) head = curr->next;
                else prev->next = curr->next;
                free(curr);
            } else {}
        }
    } else {}

    result = head;

    return result;
}


int main() {
    LinkedList_ts* head = NULL;
    LinkedList_ts* curr = NULL;
    int nodeNum, headValue, i;
    int tempValue, tempPos;
    int delValue;
    
    scanf("%d %d", &nodeNum, &headValue);
    head = LinkedList_add(head, headValue, 1);

    for (i=0; i<nodeNum-1; ++i) {
        scanf("%d %d", &tempValue, &tempPos);
        head = LinkedList_add(head, tempValue, tempPos);
    }
    scanf("%d", &delValue);
    head = LinkedList_delete(head, delValue);

    for (curr=head; curr!=NULL; curr=curr->next) {
        printf("%d ", curr->value);
    }

    return 0;
}